C# 从当前目录加载xml文件?
我在我的C#winform应用程序中使用了下面的一行,这非常有效,但是偶尔如果程序是从命令行运行的,我会收到一个错误,即找不到C# 从当前目录加载xml文件?,c#,xml,C#,Xml,我在我的C#winform应用程序中使用了下面的一行,这非常有效,但是偶尔如果程序是从命令行运行的,我会收到一个错误,即找不到config.xml文件。这是因为“工作目录”是不同的(我想),我需要说“从当前目录加载config.xml”,我该怎么做 docXML.Load("config.xml"); 谢谢 乔纳森 用于从当前目录加载 用于从基本目录加载 string fileName = Path.Combine(Application.StartupPath, "config.xml");
config.xml
文件。这是因为“工作目录”是不同的(我想),我需要说“从当前目录加载config.xml”,我该怎么做
docXML.Load("config.xml");
谢谢
乔纳森
用于从当前目录加载
用于从基本目录加载
string fileName = Path.Combine(Application.StartupPath, "config.xml");
string Path = "";
string Filename = ConfigurationManager.AppSettings("Filename");
Path = System.Web.HttpContext.Current.Server.MapPath(Filename);
Path = AppDomain.CurrentDomain.BaseDirectory + Filename;