簡體   English   中英

如何在根文件夾中保存使用XDocument在C#中創建的XML文件

[英]How to save a XML file created in C# using XDocument in Root Folder

這是我使用XDocument類創建XML文件的代碼,但是該文件保存在Debug文件夾中,我真正想要的是保存在Project內部! 謝謝

XDocument doc = new XDocument(new XElement("checkout",
                                       new XElement("currency","BRL"),
                                       new XElement("items",
                                       new XElement("item",
                                           new XElement("id", "0001"),
                                           new XElement("description", "caneca"),
                                           new XElement("amount","10.00"),
                                           new XElement("quantity","1"),
                                           new XElement("weight","50"))),
                                       new XElement("reference", "REF5678"),
                                       new XElement("sender",
                                       new XElement("name","Nathiel"),
                                       new XElement("email", "joanito@sandbox.pagseguro.com.br"),
                                       new XElement("phone",
                                       new XElement("areacode","51"),
                                       new XElement("number", "95453305"))),
                                       new XElement("shipping",
                                       new XElement("type","1"),
                                       new XElement("adress",
                                       new XElement("street","Rua da Insanidade"),
                                       new XElement("number","102"),
                                       new XElement("complement","CASA"),
                                       new XElement("district","centro"),
                                       new XElement("postalcode","54315310"),
                                       new XElement("city","Recife"),
                                       new XElement("state","PE"),
                                       new XElement("country","Brasil")))));
        doc.Save("document.xml");

您是否嘗試輸入保存文件的路徑?

doc.Save("C:\Users\(name)\Documents\document.xml");

或者可能是promt用戶將文件放在哪里:

XDocument.Save(FolderBrowserDialog.SelectedPath + "\\" + "document.xml")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM