C# 抓取程序运行路径
2015-09-18 09:01
267 查看
// 获取程序的基目录。
System.AppDomain.CurrentDomain.BaseDirectory
// 获取模块的完整路径。
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
System.Environment.CurrentDirectory
// 获取应用程序的当前工作目录。
System.IO.Directory.GetCurrentDirectory()
// 获取和设置包括该应用程序的目录的名称。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 获取启动了应用程序的可执行文件的路径。
System.Windows.Forms.Application.StartupPath
// 获取启动了应用程序的可执行文件的路径及文件名
System.Windows.Forms.Application.ExecutablePath
C# WinForm中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别示例如下:
private void Frm_Server_Load(object sender, EventArgs e)
{
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
MessageBox.Show(Application.StartupPath );
}
说明:
1. AppDomain.CurrentDomain.BaseDirectory 返回结果为: D:/mycode/
Application.StartupPath 返回结果为: D:/mycode
2. Application.StartupPath 只能用于WinForm窗体中,而AppDomain.CurrentDomain.BaseDirectory既可以用于WinForm窗体中,也可以用于类库DLL文件中.
From: http://blog.csdn.net/CYSONG168/article/details/5767533
System.AppDomain.CurrentDomain.BaseDirectory
// 获取模块的完整路径。
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
System.Environment.CurrentDirectory
// 获取应用程序的当前工作目录。
System.IO.Directory.GetCurrentDirectory()
// 获取和设置包括该应用程序的目录的名称。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 获取启动了应用程序的可执行文件的路径。
System.Windows.Forms.Application.StartupPath
// 获取启动了应用程序的可执行文件的路径及文件名
System.Windows.Forms.Application.ExecutablePath
C# WinForm中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别示例如下:
private void Frm_Server_Load(object sender, EventArgs e)
{
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
MessageBox.Show(Application.StartupPath );
}
说明:
1. AppDomain.CurrentDomain.BaseDirectory 返回结果为: D:/mycode/
Application.StartupPath 返回结果为: D:/mycode
2. Application.StartupPath 只能用于WinForm窗体中,而AppDomain.CurrentDomain.BaseDirectory既可以用于WinForm窗体中,也可以用于类库DLL文件中.
From: http://blog.csdn.net/CYSONG168/article/details/5767533
相关文章推荐
- C# Assert Method
- C# 自带的界面控件 chart,初步使用体验
- C#多线程学习 之 线程池[ThreadPool](转)
- C#编程总结 dynamic(转)
- C#方便操作数据总结
- C#中的扩展方法
- C#内存操作
- C#关于使用枚举遇到的问题----Parse()方法使用注意
- .NET基础--索引器
- C#中使用强制类型实现字符串和ASCII码之间的转换
- C#.net 多级cookie写入读取代码,一级、二级域名
- C#实现字符串数组的TreeMap排序
- C#关于使用枚举遇到的问题----Type运算符使用的必要性
- C# AttributeUsage
- C#笔记 值类型 引用类型
- C# winform 窗体间互操作(用委托与事件)
- C#实现子窗体与父窗体通信方法实例总结
- C#知识点总结:Monitor和Lock以及区别
- c#调用带输出参数的存储过程
- C# in Depth (第十章 扩展方法)