Home All Groups Group Topic Archive Search About

Tags inside value field of appsettings in web.config

Author
22 Dec 2005 12:01 PM
arulbenito
i need to write a xml data inside the value field in web.config file.
it looks likes this


<configuration>
   <appSettings>
           <add key="MyXmlData" value="<data><type></type>........." />
   </appSettings>
</configuration>

but i get an error message

some one help me

Author
22 Dec 2005 4:41 PM
Joshua Flanagan
You need to encode/escape the characters. You can do it manually if you
know all of the rules, but I wrote a little utility for myself that I
know will do it right. I guess I should post the full app at some point,
but the relevant method is:

public string Encode(string input)
{
   StringBuilder output = new StringBuilder();
   using (StringWriter stringWriter = new StringWriter(output,
CultureInfo.InvariantCulture))
   {

     XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
     xmlWriter.WriteStartElement("element");
     xmlWriter.WriteAttributeString("attribute", input);
     xmlWriter.WriteEndElement();
     xmlWriter.Close();
   }
   return output.ToString();
}


Just create a simple WinForms app with a textbox to past a value into, a
button that runs the Encode method, and then a textbox for the output
(not label - you want to be able to select the output for copy/paste).


Joshua Flanagan
http://flimflan.com/blog

Bookmark and Share