namevaluecollection

How do I access a NameValueCollection (like Request.Form or ConfigurationManager.AppSettings) as a dynamic object?

为君一笑 提交于 2019-12-12 06:09:27
问题 Is there a way to access a NameValueCollection (like Request.Form or ConfigurationManager.AppSettings) as a dynamic object? I'd like to be able to do something like this: var settings = ConfigurationManager.AppSettings.AsDynamic(); var name = settings.Name; // ConfigurationManger.AppSettings["Name"] // but also settings.Name = "Jones"; // modify the original collection // and var form = Request.Form.AsDynamic(); var email = form.Email; // Request.Form["Email"] (this question is based on

Get POST Values in ASP.NET using NameValueCollection

会有一股神秘感。 提交于 2019-12-11 14:11:37
问题 So I have 2 pages. They both have the same master page and are part of the same Web Application. I am trying to submit one page to the other. On the submitting page I have a few elements such as <ajaxToolkit:ComboBox ID="cmboOptions" AutoCompleteMode="SuggestAppend" CaseSensitive="false" ItemInsertLocation="Append" runat="server" DropDownStyle="DropDownList"> <asp:ListItem></asp:ListItem> <asp:ListItem Text="Option 1" Value="opt1"></asp:ListItem> <asp:ListItem Text="Option 2" Value="opt2"><

XML serialization of a collection in C#

牧云@^-^@ 提交于 2019-12-07 02:48:52
问题 I have two classes as follows: public class Info { [XmlAttribute] public string language; public int version; public Book book; public Info() { } public Info(string l, int v, string author, int quantity, int price) { this.language = l; this.version = v; book = new Book(author, quantity, price); } } public class Book { [XmlAttribute] public string author; public int quantity; public int price; [XmlIgnore]public int total; public NameValueCollection nvcollection = new NameValueCollection();

How to Modify HTTP Header of a request using C#?

独自空忆成欢 提交于 2019-12-06 04:17:46
问题 I was trying to modify a HTTP Header using C#. I tried to manipulate the Request.Headers on Page preinit event. But when i try to set anything to the Headers, i get PlatformNotSupportedException. Since We can not set a new NameValueCollection to Reqeust.Headers, I tried to set the value using following code: Request.Headers.Set(HttpRequestHeader.UserAgent.ToString(), "some value"); Any idea how can this be achieved? 回答1: Try this: HttpContext.Current.Request.Headers["User-Agent"] = "Some

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

巧了我就是萌 提交于 2019-12-05 15:02:41
问题 I want to have the following structure in my config: <MySection> <add key="1" value="one" /> <add key="2" value="two" /> <add key="3" value="three" /> </MySection> I have a limitation such that MySection can't use the AppSettingsSection as it has to inherit from a different parent custom section. And I need to resolve this section to a NameValueCollection such that when I call something like: ConfigurationManager.GetConfig("MySection") it should return a NameValueCollection. How to go about

How to Modify HTTP Header of a request using C#?

a 夏天 提交于 2019-12-04 10:12:15
I was trying to modify a HTTP Header using C#. I tried to manipulate the Request.Headers on Page preinit event. But when i try to set anything to the Headers, i get PlatformNotSupportedException. Since We can not set a new NameValueCollection to Reqeust.Headers, I tried to set the value using following code: Request.Headers.Set(HttpRequestHeader.UserAgent.ToString(), "some value"); Any idea how can this be achieved? Try this: HttpContext.Current.Request.Headers["User-Agent"] = "Some Value"; EDIT: This could be your reason: http://bigjimindc.blogspot.com/2007/07/ms-kb928365-aspnet

Bind NameValueCollection to GridView?

那年仲夏 提交于 2019-12-04 02:55:20
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; resultGV.DataBind(); } Code in aspx <asp:GridView ID="resultGV" runat="server" AutoGenerateColumns="False" Width="100%"> <Columns> <asp:BoundField DataField="Key" HeaderText="Key" /> <asp:BoundField DataField="Value" HeaderText="Value" /> </Columns> </asp:GridView> Any tip most welcome. Thanks. X. Can you use Dictionary<string,string> instead of NameValueCollection.

C#: Convert Dictionary<> to NameValueCollection

纵饮孤独 提交于 2019-12-03 03:05:45
问题 How can I convert a Dictionary<string, string> 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 to solve this in a generic way. Any hints? 回答1: Why not use a simple foreach loop? foreach(var kvp in dict) { nameValueCollection.Add(kvp.Key.ToString(), kvp.Value.ToString()); } This could be embedded into an extension method: public static

C#: Convert Dictionary<> to NameValueCollection

送分小仙女□ 提交于 2019-12-02 17:40:23
How can I convert a Dictionary<string, string> 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 to solve this in a generic way. Any hints? Why not use a simple foreach loop? foreach(var kvp in dict) { nameValueCollection.Add(kvp.Key.ToString(), kvp.Value.ToString()); } This could be embedded into an extension method: public static NameValueCollection ToNameValueCollection<TKey, TValue>( this IDictionary<TKey, TValue> dict) { var

NameValueCollection not available from System.Collections.Specialized

一世执手 提交于 2019-12-02 13:32:00
问题 In VS 2012 Express for Windows Phone, I am using imports of both System and System.Collections.Specialized , but I still get an error when trying to use NameValueCollection . Looking in the Object browser, I see it nested within System.dll, but there are several versions of the System dll listed - some of which do not have it. What I get in auto-complete matches the available items in the System.dll without NameValueCollection , so I'm thinking I need to sort out which System.dll is being