请向我建议一种将XML文件保存到使用C#创建的应用程序的当前安装目录中的方法。
Create an XML file: The easiest way is to create and populate an XmlDocument or XDocument object.
Save to the install directory: use
string path = System.IO.Path.GetDirectoryName(Application.ExecutablePath); string file = System.IO.Path.Combine(pathm, "myfile.xml");
But you do know that the application's folder isn't the best place to store a file, right?
Some comments mention Isolated Storage, but that is overkill. The best way to store data is to use the appropriate DataPath. That is different under various versions of Windows, but this always works:
string path =
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
There are a few other values in the Environment.SpecialFolder
enum, take a look.
Using XDocument and LINQ:
XDocument myXml = new XDocument(new XElement("Node 1", new XElement("Node 2")));
myXml.Save(Directory.GetCurrentDirectory() + "/myXML.xml");
or
XDocument myXml = new XDocument(new XElement("Node 1", new XElement("Node 2")));
myXml.Save(Path.GetDirectoryName(Application.ExecutablePath) + "/myXML.xml");
StringBuilders和HttpUtility.HtmlEncode通常可以很好地工作。
And, after you've tried everything and are still scratching your head, wondering why it isn't working...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.