C#中得到程序当前工作目录和执行目录的五种方法
来源:互联网 发布:客户信息收集软件 编辑:程序博客网 时间:2024/05/18 10:04
C#中得到程序当前工作目录和执行目录的五种方法
string str="";
str += "\r\n" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
str += "\r\n" + System.Environment.CurrentDirectory;
str += "\r\n" + System.IO.Directory.GetCurrentDirectory();
str += "\r\n" + System.AppDomain.CurrentDomain.BaseDirectory;
str += "\r\n" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
str += "\r\n" + System.Windows.Forms.Application.StartupPath;
str += "\r\n" + System.Windows.Forms.Application.ExecutablePath;
Console.Write(str);
Console.ReadKey();
得到结果:
D:\路径测试\bin\Debug\路径测试.vshost.exe
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug\
D:\路径测试\bin\Debug\
D:\路径测试\bin\Debug
D:\路径测试\bin\Debug\路径测试.EXE
1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
获取模块的完整路径。
2. System.Environment.CurrentDirectory
获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
3. System.IO.Directory.GetCurrentDirectory()
获取应用程序的当前工作目录。这个不一定是程序从中启动的目录啊,有可能程序放在C:\www里,这个函数有可能返回C:\Documents and Settings\ZYB\,或者C:\Program Files\Adobe\,有时不一定返回什么东东,我也搞不懂了。
4. System.AppDomain.CurrentDomain.BaseDirectory
获取程序的基目录。确认这种方法在 windows服务中是可以用的
5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
获取和设置包括该应用程序的目录的名称。
6. System.Windows.Forms.Application.StartupPath
获取启动了应用程序的可执行文件的路径。效果和2、5一样。只是5返回的字符串后面多了一个"\"而已
7. System.Windows.Forms.Application.ExecutablePath
获取启动了应用程序的可执行文件的路径及文件名,效果有时和1一样。
- C#中得到程序当前工作目录和执行目录的五种方法
- C#中得到程序当前工作目录和执行目录的五种方法
- C#中得到程序当前工作目录和执行目录的五种方法
- C#中得到程序当前工作目录和执行目录的五种方法
- C# 中得到程序当前工作目录和执行目录的五种方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- C#中得到程序当前工作目录和执行目录的一些方法
- C#中得到程序当前工作目录和执行目录的一些方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- C#中得到程序当前工作目录和执行目录的一些方法
- C#中得到程序当前工作目录和执行目录的一些方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- ▲【C#中得到程序当前工作目录和执行目录的一些方法】▲
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- C#中得到程序当前工作目录和执行目录的一些方法
- c#获取应用程序目录,C#中得到程序当前工作目录和执行目录方法大全
- Win7 64位中文旗舰版上Cocos2d-x 3.0的Android开发调试环境架设
- DLL入门浅析(1)——如何建立DLL
- 积分制管理系统:员工查看积分和申请非任务积分
- Android 树形菜单的 实现 ,类似美团左边是树,右边 展 ...
- java多线程管理 concurrent包用法详解
- C#中得到程序当前工作目录和执行目录的五种方法
- git使用技巧-撤销未提交修改
- Ubuntu Server12.04 Mysql 自动备份
- Android 解决android4.0系统中菜单(Menu)添加Icon无效问题
- 使用JScrollPane实现为JPanel(FlowLayout布局)增加滚动条的功能
- ArrayList与LinkedList区别总结
- DLL入门浅析(2)——如何使用DLL
- UIViewAnimation动画与Core Animation的CATransition类动画
- SpringMVC强大的数据绑定(2)——第六章 注解式控制器详解——跟着开涛学SpringMVC