Searcher
Searcher

Reputation: 1855

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

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,

Upvotes: 3

Views: 4571

Answers (3)

Habib
Habib

Reputation: 223282

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

Upvotes: 3

Pranay Rana
Pranay Rana

Reputation: 176936

try out : XmlDocument.Save Method (String)

string path =  Path.GetDirectoryName(Application.ExecutablePath) ;
changesetDB .Save( Path.Combine( path , "data.xml"));

Upvotes: 6

user1280834
user1280834

Reputation:

Your exe will be created in bin\Debug or bin\Rease so ..\ will be the bin folder. But have a look of your directories when you use your program out of vs.

changesetDB.Save("..\changesetDB.xml");

Upvotes: 0

Related Questions