I have a user control in that I embedded an xml file to store emails. Now I compiled it and made a single dll. Now I'm using this user control in a windows form and I need to write the data in that embedded xml file on a click of the button. I easily can access the data from embedded xml file by using
var doc = XDocument.Parse(Resource.EmailHistory);
var email=doc.Root.Elements().Select(x => x.Element("Email"));
foreach (string item in email)
{
textBox1.Text+= item;
}
but facing the problem while writing into the embedded xml file. please help me with this. Any help would be appreciated.
Xml Code
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Email>
Hello
</Email>
<Email>
There
</Email>
</root>
You can't write the data into an embedded XML file, because it's a resource embedded in the DLL (or an executable).
You can potentially replace it by creating an entire new resource, and then using UpdateResource. This isn't as simple as it sounds; you have to do all of the following (see Updating Resources at MSDN for details):
Having to do this much work just to update an XML file should tell you that you're going about it the wrong way, and that an embedded resource isn't the proper approach. (An external file or a database (which would allow a lot more information to be stored, and could be sorted, filtered, and searched) would be a much better solution, for instance.)