OpenFileDialog and Environment.CurrentDirectory

After using OpenFileDialog to select the file, Environment.CurrentDirectory changes to the file folder. This is normal?

From my understanding of Environment.CurrentDirectory there should always be an application folder.

+2
source share
3 answers

Because the dialog box modifies the Environment.CurrentDirectory file when searching for files or folders .. or selecting them to load ..etc ..

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

 FileDialog.RestoreDirectory property. 
+3
source

Take a look

Difference between AppDomain.CurrentDomain.BaseDirectory and Environment.CurrentDirectory

What is the difference of the following:

  • AppDomain.CurrentDomain.BaseDirectory
  • Environment.CurrentDirectory
  • AppDomainSetup.ApplicationBase

1 and 3 are basically the same. the difference is that AppDomainSetup.ApplicationBase is writable, but AppDomain.BaseDirectory is read-only, since you cannot change it after creating the appdomain.

2 is something completely different. It was used to resolve relative paths, among other things. You can change CurrentDirectory at any time in your code, and it can also be changed to such as FileDialogs.

+8
source

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

+1
source

Source: https://habr.com/ru/post/1335930/


All Articles