Tags inside value field of appsettings in web.config

A

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
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top