I plan to set up configuration keys for FormFields, QueryString parameters etc. In my web.config I have setting as follows:
<WhiteListPaametersGroup>
<WhiteListPaameters>
<FormField1>EVENTVALIDATION</FormField1>
<FormField2>VIEWSTATE</FormField2>
<FormField3>Button1</FormField3>
<QueryString1>firstname</QueryString1>
<QueryString2>lastname</QueryString2>
</WhiteListPaameters>
</WhiteListPaametersGroup>
Then in my code, I read the value as follows:
Dictionary<string, string> parameters = new Dictionary<string,string>();
foreach (XmlNode n in section.ChildNodes)
{
parameters.Add(n.Name, n.InnerText);
}
Is there a better way of storing this. Later on, I want to be able to go through dictionary like object, and be able to get settings for FormFields, Querystrings etc.
Please let me know if I could write it cleaner.
Thanks
You can use XML serialization to store your settings and restore them directly into an object. It’s not perfect but very easy to set up and gives you object save/restore.
Have this class (properties must be public):
To save it to XML file run this code:
To read it back into an object: