Using Embedded Resource in your application
When u want to attach your application assembly file additional information that located in a file (XML, Txt, image or other type) you can attach it as Embedded Resource.
The advantages I can raise for doing so r :
1.) You do not need to deploy the embedded resource attach file with your application. Its part of the assembly.
2.) You don't need to set read permissions on file system folders and files because you attach the file you need as part of your assembly
3.) You don't expose your embedded resource content as u its been done when the file you attach is not part of the assembly. This is especially what u would like to achieve when your embedded resource is an XML that define specific configuration information
How to attach a DataSet (xml/xsd files pair) to an assembly as a embedded resource:
Create two files XML, XSD that represent the DataSet
u should right click on each of the files-->choose properties
In properties window u should set the Build Action value to embedded resource
In order to retrieve the resources and construct the DataSet from the XML/XSD we should do the following:
We first define in the Global class a static member that will be use to hold the loaded DataSet
internal
static DataSet dsErrors=null; //we will keep there different Error Messages
[Static members at the Global class in web applications r excellent for sharing at application level - with performance advantage over Application collection object]
Then we need to load the DataSet
protected
void Application_Start(Object sender, EventArgs e)
{
Global.dsErrors =
new DataSet("Errors");
string xmlResouce = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".ApplicationErrors.xsd";
using (Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlResouce))
{
Global.dsErrors.ReadXmlSchema(s);
}
xmlResouce = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".ApplicationErrors.xml";
using (Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlResouce))
{
Global.dsErrors.ReadXml(s);
}
}
by using xml file to hold global application information we can enjoy the VS.NET XML editor which enables us an easy way to edit our file, sorting the data within it and browsing it when we have hierarchy data