I want to create an xml file. I know how to create an xml file using linq to xml concept. But i want to save that file in the bin folder of my project. How to do that.
XDocument changesetDB = new XDocument(
new XElement("changes",
new XElement("change",
new XAttribute("path", changedFile),
new XAttribute("changesetID", changesetID),
new XAttribute("JIRAID", issueID))));
Now i want to save it in bin folder. Is it possible to do like that. Thanks,
try out : XmlDocument.Save Method (String)
string path = Path.GetDirectoryName(Application.ExecutablePath) ;
changesetDB .Save( Path.Combine( path , "data.xml"));
changesetDB.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"myfile.xml"));
it will save myfile.xml in bin/debug folder
But if you want to save file to the bin folder, not the debug or release then you have to strip the Debug part of path from the path. You can do the following.
string binDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(@"Debug\\".ToCharArray());
changesetDB.Save(Path.Combine(binDir,"myfile.xml"));
This will save the file myfile.xml to the bin folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With