Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create an xml document in c# and store that file into bin folder of the project

Tags:

c#

linq-to-xml

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,

like image 342
Searcher Avatar asked Dec 07 '25 07:12

Searcher


2 Answers

try out : XmlDocument.Save Method (String)

string path =  Path.GetDirectoryName(Application.ExecutablePath) ;
changesetDB .Save( Path.Combine( path , "data.xml"));
like image 167
Pranay Rana Avatar answered Dec 08 '25 20:12

Pranay Rana


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

like image 34
Habib Avatar answered Dec 08 '25 21:12

Habib