473,408 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Saving a XML Document as Resource

Hello,
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....

Thanks,
Sebastián Sassi
Jul 21 '05 #1
2 1545
> 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

Jul 21 '05 #2
Thank u very much !!
Your answer was very useful for me.

Sebastián Sassi...
"Marc Scheuner [MVP ADSI]" <m.********@inova.SPAMBEGONE.ch> escribió en el
mensaje news:9k********************************@4ax.com...
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.YourXmlDocN
ame");
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

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I...
0
by: Philippe Poulard | last post by:
A sane document management approach: I manage my documents with a key, composed with some fields of my XML documents. When I have to refer to documents, I use a canonical form of the key so that...
6
by: Vijay | last post by:
I need to generate HTML files based on the some codes. One HTML file per code. I have the link (ex:http://123.234.345.456/WebPages/GetTestData.aspx?SomeCode=25), by passing the code as parameter I...
4
by: Jim | last post by:
Hi I'm looking to take an existing XML document, query for certain nodes, and 'recreate' the document with just the relevant nodes. I'm currently using XPath - I have established the pattern that...
1
by: Kevin | last post by:
I have the following Xml document (see end of post) with many external resources that need to get resolved. When I "view" the Xml document in Internet Explorer (Windows XP SP2, IE 6.0.2900) all of...
0
by: Bill | last post by:
I have a strong typed dataset which I load using the following code. try { XmlTextReader xmlTR = new XmlTextReader("XIF-v1.0.xsd"); dsMyDataSet.ReadXmlSchema(xmlTR); if (p_FileName !=...
2
by: Sebastián Sassi | last post by:
Hello, 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.... Thanks, Sebastián...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
3
by: thompson_38 | last post by:
I am currently working on a C# application that uses an axWebBrowser control which displays HTML pages. This is being done to reuse an existing web application which resides on a client's...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.