System.Environment.CurrentDirectory

Application.StartupPath

https://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath(v=vs.110).aspx

System.Environment.CurrentDirectory

https://msdn.microsoft.com/en-us/library/system.environment.currentdirectory(v=vs.110).aspx

百度之后,找到区别

System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,
而Application.StartupPath是获取程序启动路径,
表面上看二者没什么区别,但实际上区别大得很。

先说前者:比如说你程序放在桌面上启动,但是中间你用了一个OpenFileDialog打开了E盘名为abc的文件夹下的某一个文件,那么CurrentDirectory就变成E:\abc了,
所以如果你想再获取程序启动文件夹的某一个文件就没用了,

但是Application.StartupPath就不会这样了,无论你中间打开了哪个盘的文件,启动路径都是在桌面那里,一直不会变。

http://stackoverflow.com/questions/1343406/environment-currentdirectory-is-yielding-unexpected-results-when-running-install

If you want to get the path to the directory under which your executable runs, you should not rely on the Environment.CurrentDirectory,

since it can be changed in a number of ways (shotrtcut settings, etc). Try one of these options instead:

http://stackoverflow.com/questions/1321628/environment-currentdirectory-in-c-net

You shouldn't be using the Environment.CurrentDirectory value as a base for file lookups because it can change and may not always be under your control. e.g. a File Save As to a different folder may change the 'current folder' value. As you can see it can yield unpredictable results.

Use a value that you can control better. e.g. a ResourcesFolderPath value in a configuration (xml?) file that is updated when you install your app.

Desktop 和 DesktopDirectory

https://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.110).aspx

Desktop :The logical Desktop rather than the physical file system location.

DesktopDirectory:he directory used to physically store file objects on the desktop.

What's the difference between SpecialFolder.Desktop and SpecialFolder.DesktopDirectory?

A directory is a location in the file system.

A folder is a location in the shell namespace.

A directory is a kind of folder.

A virtual folder is not necessarily backed by a directory.

For example consider libraries or search folders.

The user's desktop directory is a location in the file system.

The desktop folder merges that with virtual items like all users items, recycle bin, shortcut to documents folder etc.

最新文章

  1. DSP中.gel文件的作用
  2. CardView
  3. 技术分析:Femtocell家庭基站通信截获、伪造任意短信
  4. .Net程序员安卓学习之路2:访问网络API
  5. pip安装使用详解
  6. Database File Management ->> Shrink Data File
  7. C语言中用宏来作注释
  8. 也用 Log4Net 之走进Log4Net (四)
  9. php中的数组定义和使用
  10. java +bootstrap table 完整例子
  11. MS SQL Server递归查询
  12. 全局鼠标钩子:WH_MOUSE_LL, 在【 win 10 上网本】上因为太卡,运行中丢失全局鼠标钩子
  13. python控制语句---循环结构语句
  14. 洛谷P1792 [国家集训队]种树(链表 贪心)
  15. 网络拓扑自动发掘之三层设备惯用的SNMP OID的含义
  16. 5句话搞定ES5作用域
  17. Lamport Logical Clock 学习
  18. C#+三层+会员管理系统源码
  19. 团体程序设计天梯赛L2-023 图着色问题 2017-04-17 09:28 269人阅读 评论(0) 收藏
  20. CentOS的rpm常用命令(转)

热门文章

  1. phpStorm中ftp的配置与使用,支持配置多个
  2. Ubuntu桌面基础介绍
  3. Java-MyBatis:MyBatis 中 in 的用法
  4. JSTL中的常用EL函数(fn:contains(str,subStr))
  5. 解决 Eclipse 导入项目后 Maven Dependencies missing jar 问题
  6. c#中集成Swagger
  7. c# post方式请求java form表单api
  8. mybatis的sql语句导致索引失效,使得查询超时
  9. Linux top命令简解
  10. Web前端必须规避的8个误区