Directory.GetCurrentDirectory和Application.StartupPath的区别
System.IO.Directory.GetCurrentDirectory()方法用于获得应用程序当前工作目录。
System.Windows.Forms.Application.StartupPath 获得应用程序的可执行文件的路径,不含文件名
StartupPath 可执行文件固定就不会变,可用于定位
GetCurrentDirectory 不一定是可执行文件所在目录,因启动的位置而变
如有两个程序 C:/A/a.exe 和 C:/B/b.exe
当在 a.exe 中启动 b.exe,System.Diagnostics.Process.Start(@"C:/B/b.exe")
这时,b.exe 中 Directory.GetCurrentDirectory()方法 返回值为“C:/A”,Application.StartupPath 值为“C:/B”
如果直接在 C:/B/ 中启动 b.exe,那么两个值就会一样,都为“C:/B”
这就是 Directory.GetCurrentDirectory 和 Application.StartupPath 的区别
两个意义是不一样的.
Application.StartupPath是程序的启动目录,这个在程序运行以后,就不会改变了.
Directory.GetCurrentDirectory()是 "当前目录 ",是可以在程序运行时候改变的,用
Directory.SetCurrentDirectory()就可以改变.
Directory.GetCurrentDirectory()的缺省值是和Application.StartupPath()一样的.
Directory.GetCurrentDirectory和Application.StartupPath的区别的更多相关文章
- 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别
原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...
- C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
// 获取程序的基目录. System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径. System.Diagnostics.Process.G ...
- 【摘抄】Application.StartupPath和System.Environment.CurrentDirectory的区别
System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,而Application.StartupPath是获取程序启动路径,表面上看二者没什么区别,但实际 ...
- Application.StartupPath和System.Environment.CurrentDirectory的区别
System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,而Application.StartupPath是获取程序启动路径,表面上看二者没什么区别,但实际 ...
- Application.StartupPath同System.Environment.CurrentDirectory区别
System.Windows.Forms.Application.StartupPath:获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称. System.Environment.Curr ...
- System.Environment.CurrentDirectory和Application.StartupPath
System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,而Application.StartupPath是获取程序启动路径,表面上看二者没什么区别,但实际 ...
- 【CITE】当类库项目中无法使用Application.StartupPath的时侯 (注:主要是在进行反射读取文件的时候!!)
http://jcserver.blog.163.com/blog/static/24044859200851582354135/ 通常我们WinForm编程时,要获取程序当 前运行的文件夹路径会用A ...
- 当类库项目中无法使用Application.StartupPath
通常我们WinForm编程时,要获取程序当前运行的文件夹路径会用Application.StartupPath ,但是Application.StartupPath在编写类库项目时却无法使用,因为我们 ...
- Directory.GetCurrentDirectory
1.一个应用程序中,Directory.GetCurrentDirectory获得的当前工作目录是C:\Windows\System32,这是为什么呢?是如何设置的? 2.在WinXP下:System ...
随机推荐
- 使用VS2010开发Qt程序的一点经验(转载)
转载:http://www.cnblogs.com/csuftzzk/p/VS_Qt_Experience.html 导读 相比于Qt Creator,我更喜欢用VS2010来进行开发.虽然启动时间相 ...
- 将XML文件中的内容转换为Json对象
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;u ...
- UVA 10534 三 Wavio Sequence
Wavio Sequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- CodeForces 131A cAPS lOCK
cAPS lOCK Time Limit:500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- ubuntu vi/vim编辑器必知必会
转载出处:http://blog.csdn.net/xiajun07061225/article/details/7039413 一.我们为什么要学习vim编辑器? Linux的命令行界面下面有非常多 ...
- How to: Update an .edmx File when the Database Changes
https://msdn.microsoft.com/en-us/library/cc716697.aspx In the Model Browser, right-click the .edmx f ...
- Berkeley 四种产品如何选择?
Berkeley 四种产品如何选择? 四种产品综览 Berkeley 可供选择的四款产品: DS: 简单的.支持单写单读的数据存储:支持高并发,多进程同时读操作:不支持锁,这就意味着当程序在进行更新和 ...
- git学习笔记02-创建一个仓库提交一个文件-原来就是这么简单
打开安装好的git bash,设置你的git信息 (这个随便写就行) 初始化一个Git仓库,分三步.(创建文件夹也可以手动创建,也可以命令行创建) 第一步,进到一个目录 cd e: 第二步,创建一 ...
- linux使用脚本自动连接数据库
脚本名: mtest1.sh #!/bin/bash # test connecting to the Mysql server MYSQL=`which mysql` $MYSQL test -u ...
- iOS - UITextField
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextField : UIControl <UITextInput, NSCoding> @ava ...