I would like to know how can I save an XML Document used to store
data as an internal file.... something like a resource file, so the user
can't read or modify it....
1) Store the XML to a file on your disk
2) Add the file to your project
3) Select that file in your Solution Explorer
4) Set the "Build Action" to "Embedded Resource"
To access this later on, do this:
1) Get the assembly's "Manifest Resource Stream"
Stream stmXmlData =
this.GetType().Assembly.GetManifestResourceStream("YourNameSpace.YourXmlDocName");
Be careful to get the name of the resource stream right - you have to
concatenate the name space of your assembly (e.g. "YourNameSpace") and
the name of the XML document in your project (e.g. "YourXmlDoc") right
- if you used a file name like "MyDoc.xml", then you need to specify
that full name, including the extension!
2) Read the contents of the XML document from the stream into e.g. a
string:
StreamReader oSR = new StreamReader(stmXmlData);
string sXmlString = oSR.ReadToEnd();
oSR.Close();
That's it !! Now you have your XML Document as a string (as if you
loaded it off the disk), and you can use it any way you need.
Works very well, and with all kinds of resources, really.
Marc