Reputation: 255
I'm a very beginner with c#
.
I write a little XML
converter. In the debug mode saves my xml files under bin/debug.
I use:
XmlWriter xw = XmlWriter.Create("Filename.xml")
When I compile the code and run it, the xml are not saved. What can I do to ensure that the xml is stored at a particular path? The save Location path comes from a form as a string
Upvotes: 0
Views: 2668
Reputation: 349
You just need to combine the path and the xml file name, then use XmlWriter
to write xml element:
string pathName = Path.Combine(location, "Filename.xml"); // location is the string from your form.
using (var xw = XmlWriter.Create(pathName))
{
xw.WriteStartElement("myxml");
}
Upvotes: 2
Reputation: 2703
XmlWriter creates a new XmlWriter instance using the filename and XmlWriterSettings object. (Not saving the file!)
When you have the xml you can save it using System.IO:
File.WriteAllText(saveLocationPath, yourXML);
Upvotes: 0