[英]create an xml document in c# and store that file into bin folder of the project
我想創建一個xml文件。 我知道如何使用linq to xml概念創建一個xml文件。 但我想將該文件保存在我項目的bin文件夾中。 怎么做。
XDocument changesetDB = new XDocument(
new XElement("changes",
new XElement("change",
new XAttribute("path", changedFile),
new XAttribute("changesetID", changesetID),
new XAttribute("JIRAID", issueID))));
現在我想將它保存在bin文件夾中。 是否可以這樣做。 謝謝,
試試: XmlDocument.Save方法(String)
string path = Path.GetDirectoryName(Application.ExecutablePath) ;
changesetDB .Save( Path.Combine( path , "data.xml"));
changesetDB.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"myfile.xml"));
它會將myfile.xml
保存在bin/debug
文件夾中
但是,如果要將文件保存到bin
文件夾,而不是調試或發布,則必須從路徑中刪除路徑的Debug部分。 您可以執行以下操作。
string binDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(@"Debug\\".ToCharArray());
changesetDB.Save(Path.Combine(binDir,"myfile.xml"));
這會將文件myfile.xml
保存到bin
文件夾中
你的exe將在bin \\ Debug或bin \\ Rease中創建,所以.. \\將是bin文件夾。 但是當你使用你的程序時看看你的目錄
changesetDB.Save("..\changesetDB.xml");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.