读书人

C#获取本程序所在路径解决方案

发布时间: 2012-05-21 18:04:41 作者: rapoo

C#获取本程序所在路径
有一个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"); 

读书人网 >C#

热点推荐