You can create a new writeable instance of HttpValueCollection
by calling System.Web.HttpUtility.ParseQueryString(string.Empty)
, and then use it as any NameValueCollection
. Once you have added the values you want, you can call ToString
on the collection to get a query string, as follows:
NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty);
queryString.Add("key1", "value1");
queryString.Add("key2", "value2");
return queryString.ToString(); // Returns "key1=value1&key2=value2", all URL-encoded
The HttpValueCollection
is internal and so you cannot directly construct an instance. However, once you obtain an instance you can use it like any other NameValueCollection
. Since the actual object you are working with is an HttpValueCollection
, calling ToString method will call the overridden method on HttpValueCollection
, which formats the collection as a URL-encoded query string.
After searching SO and the web for an answer to a similar issue, this is the most simple solution I could find.
.NET Core
If you're working in .NET Core, you can use the Microsoft.AspNetCore.WebUtilities.QueryHelpers
class, which simplifies this greatly.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.webutilities.queryhelpers
Sample Code:
const string url = "https://customer-information.azure-api.net/customers/search/taxnbr";
var param = new Dictionary<string, string>() { { "CIKey", "123456789" } };
var newUrl = new Uri(QueryHelpers.AddQueryString(url, param));
For a sample app.config file like below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="countoffiles" value="7" />
<add key="logfilelocation" value="abc.txt" />
</appSettings>
</configuration>
You read the above application settings using the code shown below:
using System.Configuration;
You may also need to also add a reference to System.Configuration
in your project if there isn't one already. You can then access the values like so:
string configvalue1 = ConfigurationManager.AppSettings["countoffiles"];
string configvalue2 = ConfigurationManager.AppSettings["logfilelocation"];
Best Answer
Well I don't know if the comparison is valid..
ResX is a storage format for storing resources in XML. It gets compiled to a binary form (.resources) with the resgen tool before it gets embedded (if so specified) into the assembly.
Satellite assembly is a diff/delta of your main assembly resources and your localized resources. So if you have a Strings.resx with 100 strings in MainAssembly.dll of which 10 change in French Canadian Culture, you should have a MainAssembly.resources.dll (satellite assembly) containing just those 10 strings in the fr-CA subdirectory of the DLL folder. When you query for a string resource using a ResourceManager, it takes into account current culture. If fr-CA, it will first look for the string in the satellite assembly in the fr-CA folder, if not found it will fall back to the resources in the DLL itself and return that. The mechanism is to search for it in the following order always.
For more details, check out http://www.dotneti18n.com/ or the Resources chapter of 'Programming WPF'