C#获取本程序所在路径解决方案
C#获取本程序所在路径
有一个C#控制台程序,在它执行成功后生成的Debug文件夹里新增了一个XML文件,现在想从该XML文件中读取数据,读取路径该怎么表示?
------解决方案--------------------
AppDomain.CurrentDomain.BaseDirectory
------解决方案--------------------
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
当前程序运行路径
------解决方案--------------------
是这个???
有一个C#控制台程序,在它执行成功后生成的Debug文件夹里新增了一个XML文件,现在想从该XML文件中读取数据,读取路径该怎么表示?
------解决方案--------------------
AppDomain.CurrentDomain.BaseDirectory
------解决方案--------------------
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
当前程序运行路径
------解决方案--------------------
是这个???
- C# code
//获取到bin目录的下层路径:bin\Debug\ string aa = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string cc = System.AppDomain.CurrentDomain.BaseDirectory; //获取到bin目录:bin\Debug string dd = System.Environment.CurrentDirectory; string ee = System.IO.Directory.GetCurrentDirectory(); string ff = System.Windows.Forms.Application.StartupPath; //获取程序.exe string bb = System.Windows.Forms.Application.ExecutablePath;
------解决方案--------------------
- C# code
string filePath = Application.StartupPath + @"/aaa.xml";
------解决方案--------------------
- C# code
XmlDocument mydom = new XmlDocument(); mydom.Load(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)+ @"\xxx.xml");