Questions tagged [namevaluecollection]

NameValueCollection is a .Net collection of string keys and string values that can be accessed either with by key or by the index.

NameValueCollection is a .Net collection of string keys and string values that can be accessed either with by key or by the index.

References

116 questions
358
votes
33 answers

Parse a URI String into Name-Value Collection

I've got the URI like this: https://google.com.ua/oauth/authorize?client_id=SS&response_type=code&scope=N_FULL&access_type=offline&redirect_uri=http://localhost/Callback I need a collection with parsed elements: NAME …
Sergey Shafiev
  • 4,205
  • 4
  • 26
  • 37
169
votes
12 answers

Check if Key Exists in NameValueCollection

Is there a quick and simple way to check if a key exists in a NameValueCollection without looping through it? Looking for something like Dictionary.ContainsKey() or similar. There are many ways to solve this of course. Just wondering if someone can…
supersuf
  • 1,793
  • 2
  • 11
  • 12
107
votes
3 answers

NameValueCollection vs Dictionary

Possible Duplicate: IDictionary or NameValueCollection Any reason I should use Dictionary instead of NameValueCollection? (in C# / .NET Framework) Option 1, using NameValueCollection: //enter…
frankadelic
  • 20,543
  • 37
  • 111
  • 164
90
votes
12 answers

NameValueCollection to URL Query?

I know i can do this var nv = HttpUtility.ParseQueryString(req.RawUrl); But is there a way to convert this back to a url? var newUrl = HttpUtility.Something("/page", nv);
user34537
82
votes
8 answers

C# Iterate through NameValueCollection

I have a NameValueCollection, and want to iterate through the values. Currently, I’m doing this, but it seems like there should be a neater way to do it: NameValueCollection nvc = new NameValueCollection(); nvc.Add("Test", "Val1"); nvc.Add("Test2",…
Paul Michaels
  • 16,185
  • 43
  • 146
  • 269
66
votes
7 answers

Make NameValueCollection accessible to LINQ Query

How to make NameValueCollection accessible to LINQ query operator such as where, join, groupby? I tried the below: private NameValueCollection RequestFields() { NameValueCollection nvc = new NameValueCollection() …
Graviton
  • 81,782
  • 146
  • 424
  • 602
56
votes
7 answers

How to know if an HTTP request header value exists

Very simple I'm sure, but driving me up the wall! There is a component that I use in my web application that identifies itself during a web request by adding the header "XYZComponent=true" - the problem I'm having is, how do you check for this in…
Jimbo
  • 22,379
  • 42
  • 117
  • 159
49
votes
4 answers

how to convert NameValueCollection to JSON string?

I tried: NameValueCollection Data = new NameValueCollection(); Data.Add("foo","baa"); string json = new JavaScriptSerializer().Serialize(Data); it returns: ["foo"] I expected {"foo" : "baa"} How do I to do this?
The Mask
  • 17,007
  • 37
  • 111
  • 185
41
votes
7 answers

Copy key values from NameValueCollection to Generic Dictionary

Trying to copy values from an existing NameValueCollection object to a Dictionary. I have the following code below to do that but seems the Add does not accept that my keys and values are as Strings IDictionary dict = new…
Kobojunkie
  • 6,375
  • 31
  • 109
  • 164
37
votes
7 answers

Get all values of a NameValueCollection to a string

I have the following code: string Keys = string.Join(",",FormValues.AllKeys); I was trying to play around with the get: string Values = string.Join(",", FormValues.AllKeys.GetValue()); But of course that doesn't work. I need something similar to…
Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93
35
votes
3 answers

C#: Convert Dictionary<> to NameValueCollection

How can I convert a Dictionary to a NameValueCollection? The existing functionality of our project returns an old-fashioned NameValueCollection which I modify with LINQ. The result should be passed on as a NameValueCollection. I want…
321X
  • 3,153
  • 2
  • 30
  • 42
14
votes
4 answers

how to convert an instance of an anonymous type to a NameValueCollection

Suppose I have an anonymous class instance var foo = new { A = 1, B = 2}; Is there a quick way to generate a NameValueCollection? I would like to achieve the same result as the code below, without knowing the anonymous type's properties in…
Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130
12
votes
2 answers

How to create a custom section that behaves like an AppSettings section?

I want to have the following structure in my config: I have a limitation such that MySection can't use the AppSettingsSection…
Sidharth Panwar
  • 4,606
  • 6
  • 27
  • 36
12
votes
5 answers

Reverse function of HttpUtility.ParseQueryString

.Net's System.Web.HttpUtility class defines the following function to parse a query string into a NameValueCollection: public static NameValueCollection ParseQueryString(string query); Is there any function to do the reverse (i.e. to convert a…
Palani
  • 8,962
  • 11
  • 53
  • 62
9
votes
6 answers

Bind NameValueCollection to GridView?

What kind of collection I should use to convert NameValue collection to be bindable to GridView? When doing directly it didn't work. Code in aspx.cs private void BindList(NameValueCollection nvpList) { resultGV.DataSource = list; …
Jaroslav Urban
  • 1,269
  • 3
  • 20
  • 32
1
2 3 4 5 6 7 8