Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am trying to save an xml file to a specific file
path. I do succeed in creating the xml file, but not
where I want it.

This is what I used:

C#
XmlTextWriter writer = new XmlTextWriter("test.xml", null);


Please any help would be appriciated!!
Posted
Updated 23-Aug-18 8:58am
Comments
Herman<T>.Instance 11-May-12 6:57am    
Just add the path to the filename

So, what is the issue? Just modify the path variable as below:
C#
string path = "C:\\test.xml";
XmlTextWriter writer = new XmlTextWriter(path , null);
 
Share this answer
 
Have a look at these:
MSDN: XmlDocument.Save Method[^]
MSDN Support: How To Modify and Save XML with the XmlDocument Class in the .NET Framework SDK[^]
Video: Write a XML file[^]

For example:
C#
//save xml file at the given location
xmlDoc.Save(@"E:\My Projects\Test\data.xml");
 
Share this answer
 
v2
This one is the best solution i've found to save the xml "doc" well formatted to file "data.xml":

XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
// Save the document to a file and auto-indent the output.
using (XmlTextWriter writer = new XmlTextWriter("data.xml", null)) {
    writer.Formatting = Formatting.Indented;
    doc.Save(writer);
}
 
Share this answer
 

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