Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I embedded a xml file in Resource files.
In programme code, I need to read this xml and edit the content, then save it to Resource file.
But how to save the changed content to Resource files?
Posted

Hi Kean,

You cant do this. Resource files are compiled in a special format and attached in your application. See this http://msdn.microsoft.com/en-us/library/f45fce5x(v=VS.80).aspx. I think you will find it usefull.

If you want to edit an xml file during runtime, dont embed it in resources. Store it anywhere on your disk and access that path.
 
Share this answer
 
Comments
Dalek Dave 4-Nov-10 4:51am    
Good Call.
Kean(cn) 4-Nov-10 6:32am    
Thank you dmageiras!
And I had tried another way: I add a xml file to the Resource files(embedded), then run the programme, use script to create a new Resource file to overide orignal xml file.. but fail finally.

Seems I should give up the action of modifying Resource file..
Hi kean.. i was also having the same problem that you were facing. i had also posted questions on CodeProject earlier but had no success. Finally after doing a lot of "google" and books,what i found is that :

1. You cannot edit an Embedded Resource.

2. The XML file should not be kept as a resource as said by dmageiras. So what you can do is either
a)store it in some disk and access
or do it in my way :
b)make the Build Action of your XML to Content and then change the Copy
to Output Directory option to Copy Always.
with this the XML file will automatically go to the debug folder and
accessing XML will be much simpler:
to Load:
ie.
XmlDocument xmlDoc=new XmlDocument();
      xmlDoc.Load("myXmlFile.Xml");

to Save:
xmlDoc.Save("myXmlFile.xml");


It is also recommended that if you want to edit any resource, it is better to keep it as Content File. After reading a number of books, the authors have warned that never keep your resource as Embedded Resource.

You can also have a look at this MSDN link :
http://msdn.microsoft.com/en-us/library/bbwz4bhx%28v=VS.80%29.aspx

Another link which will be very helpful! :
http://forums.silverlight.net/forums/p/152118/339496.aspx

I hope now you know what the correct way is!

make a simple project and try to do it. after you run your project for first time, you can check in the debug folder of your project where you can find your XML. make some changes through code on that XML and it gets reflected in that XML itself.

Good Luck! :)
 
Share this answer
 
v3
Comments
Kean(cn) 4-Nov-10 6:33am    
Thanks very much!
And I had tried another way: I add a xml file to the Resource files(embedded), then run the programme, use script to create a new Resource file to overide orignal xml file.. but fail finally.

Seems I should give up the action of modifying Resource file..
Tarun.K.S 4-Nov-10 7:12am    
You just have to set its build action to Content! then you can easily edit or modify!!i have made a project using XML and modified it too.
Tarun.K.S 4-Nov-10 7:41am    
You can also have a look at this link too : http://www.codeproject.com/KB/WPF/WPFandXML.aspx
Kean(cn) 5-Nov-10 2:51am    
"build action to Content"..so will user could see the xml? I dont want user see/find it in programme file.
But i allow user could export and import this xml file.

Sorry, now my VS version is 2005, cant read the file of link
Tarun.K.S 5-Nov-10 4:18am    
no the user wont be able to see or find it.

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