C# 如何在wpf中获取当前应用程序路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10926506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get current application path in wpf
提问by Chandru A
public XML()
{
this.InitializeComponent();
XmlDocument document_name = new XmlDocument();
XmlElement student = document_name.CreateElement("Student");
XmlElement name = document_name.CreateElement("Chandru");
student.AppendChild(name);
document_name.AppendChild(student);
XmlAttribute id = document_name.CreateAttribute("ID");
name.SetAttributeNode(id);
id.Value = "sst5038";
XmlElement fname = document_name.CreateElement("FName");
fname.InnerText = "Anjappn";
name.AppendChild(fname);
XmlElement mname = document_name.CreateElement("MName");
mname.InnerText = "Thaiyamuthu";
name.AppendChild(mname);
document_name.AppendChild(student);
document_name.Save(@"D:\student.xml");
}
with above code.I create one xml file as code behind in wpf and i save this file in my local disk D:\student.xml
使用上面的代码。我在 wpf 中创建一个 xml 文件作为代码,并将此文件保存在本地磁盘 D:\student.xml
document_name.Save(@"D:\student.xml");
But i want to save this xml file (student.xml) in my project file which i am working now.
但我想将这个 xml 文件 (student.xml) 保存在我现在正在工作的项目文件中。
what should i do for this.
我该怎么做。
please help me...
请帮我...
采纳答案by Markus
Is this the property you're looking for?
这是您要找的物业吗?
System.AppDomain.CurrentDomain.BaseDirectory
回答by Andrey Atapin
System.IO.Directory.GetCurrentDirectory();will help you. Note that the string returned doesn't end with a backslash.
System.IO.Directory.GetCurrentDirectory();会帮助你。请注意,返回的字符串不以反斜杠结尾。
回答by Nikhil Agrawal
Use
用
Directory.GetCurrentDirectory();
It works both in WPF and Winforms because its a function in C# and is not specific to WPF or Winforms.
它适用于 WPF 和 Winforms,因为它是 C# 中的一个函数,并且不特定于 WPF 或 Winforms。

![C# Web 应用程序项目 [...] 被配置为使用 IIS。找不到 Web 服务器 [...]。](/res/img/loading.gif)