开发者

OpenFileDialog and Environment.CurrentDirectory

开发者 https://www.devze.com 2022-12-16 17:05 出处:网络
After using the OpenFileDialog for selecting a file the Environment.CurrentDirectory changes to the folder of the file. Is this normal?

After using the OpenFileDialog for selecting a file the Environment.CurrentDirectory changes to the folder of the file. Is this normal?

From my understanding Envir开发者_JAVA百科onment.CurrentDirectory should always be the application folder.


Have a look at

Difference of AppDomain.CurrentDomain.BaseDirectory and Environment.CurrentDirectory

What is the difference of the follows ?

  1. AppDomain.CurrentDomain.BaseDirectory
  2. Environment.CurrentDirectory
  3. AppDomainSetup.ApplicationBase

1 and 3 are basically thr same. The difference is that AppDomainSetup.ApplicationBase is writable, but AppDomain.BaseDirectory is read-only since you can't change it after the appdomain has been created.

2 is something entirely different. It's used to resolve relative paths, among other things. You can change the CurrentDirectory at any time in your code, and it may also be changed by things like the FileDialogs.


Because the dialog box changes the Environment.CurrentDirectory while searching for files or folders .. or selecting them for upload..etc..

Note: as indicated in the comment to you question, following the link to the duplicate question.. use

FileDialog.RestoreDirectory property.


Yes it's normal, and no the current directory is not always the application folder. Run cmd and use the cd command to change the directory. You've just changed the same value that appears in Environment.CurrentDirectory! You should only ever be using the current directory value when the user specifies a file name through the command line or a similar mechanism. If you want the application folder use the Application.StartupPath property.

0

精彩评论

暂无评论...
验证码 换一张
取 消