在成功运行后,我有下面的代码来编写它存储在Bin文件夹中的XML.But。问题是:我想将它存储在指定的可配置网络位置,而不是Bin文件夹中。有什么想法吗?
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
// Add a price element.
XmlElement newElem = doc.CreateElement("price");
newElem.InnerText = "10.95";
doc.DocumentElement.AppendChild(newElem);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
// Save the document to a file and auto-indent the output.
XmlWriter writer = XmlWriter.Create("data.xml", settings);
doc.Save(writer);谢谢
发布于 2014-11-16 19:30:57
您只需在那里通过一条路径,而不是data.xml
XmlWriter.Create("C:\MyFolder\data.xml");由于您希望它是可配置的,我建议您使用App.Config和ConfigurationManager来设置您想要的路径。
基本上它看起来像这样
(在代码中:)
string path = ConfigurationManager.AppSettings["SaveFilePath"];(App.Config:)
<configuration>
<appSettings>
<add key="SaveFilePath" value="C:\BlaBla\data.xml"/>
</appSettings>
</configuration>https://stackoverflow.com/questions/26961122
复制相似问题