For some situation, I need to save data or configuration as a default to the DLL and EXE files. First I make XML file in Visual Studio and fill the contents. After that set XML file’s Build Action to Embedded Resource. After compiling and produce DLL or EXE you can access the resources using the methods below.
/// <summary>
/// Get XML from Embedded Resources
/// </summary>
/// <returns></returns>
public XmlReader GetXmlConfig()
{
XmlReader xmlReader = null;
Assembly asm = Assembly.LoadFrom(“myLibrary.dll”);
if (asm != null)
{string[] strArr = asm.GetManifestResourceNames();
if (strArr != null && strArr.Length > 0){
foreach (string str in strArr)
{if (str.EndsWith(“MyXML.xml”))
{Stream stream = asm.GetManifestResourceStream(str);
xmlReader = XmlReader.Create(stream);}
}
}
} return xmlReader;
}