Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have added a .xml file to application resources.
Now I want to access that xml file and fill dataset using that xml file in c#.net

Can anyone help that how can i do this in C#.net
Posted

A little googling goes a LONG way:

C#
XDocument doc = XDocument.Parse(MyProject.Properties.Resources.XMLFile);
 
Share this answer
 
Comments
Tarun.K.S 15-Apr-11 9:14am    
Comment from OP:

Thanx john

But how do i fill the dataset with this XDocument.
If you use .RESX resource it will create two files for you. Look at the generated C# class. Never touch it, it will be auto-generated every time you change anything in the resources. Locate the generated static class and static property; the property name should be the same or close to the XML file name. Use this property, it will represent the content of the file. Use this variable (and nothing else; don't retrieve resource manually via Resource Manager — it's already done for you).

To fill a dataset, treat the content of the file as a string resource. You can read it with System.Xml.XmlReader, create XML document out of it, etc.

—SA
 
Share this answer
 
v2
I got the perfect Answer for it.
Here it is the code

DataSet ds = new DataSet();
   XDocument doc = XDocument.Parse(Namespace.Properties.Resources.Name);
   ds.ReadXml(doc.CreateReader());
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900