首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-05-21 
C#获取本程序所在路径有一个C#控制台程序,在它执行成功后生成的Debug文件夹里新增了一个XML文件,现在想从

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"); 

热点排行