1

I am using Visual Studios 2019 Community using the .Net Framework 4.7.2. Using OpenFiledialog my InitialDirectory is set to Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures). According to Microsoft Docs Website "The file system directory that serves as a repository for image files common to all users. Added in the .NET Framework 4." However, when I run my application I am placed in my personal pictures folders. My understanding is that the folder common to all users should be the Public Pictures folder. Is this an issue with Windows 10 Professional or am I missing something.

Here is my code

     using(OpenFileDialog GetPhoto = new OpenFileDialog())
        {
            GetPhoto.InitialDirectory = 
       Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures);

enter image description here

  • I am also on Windows 10 Pro. In Windows PowerShell, `[Environment]::GetFolderPath('CommonPictures')` returns `C:\Users\Public\Pictures`. `$PSVersionTable` shows `4.0.30319.42000` for `CLRVersion`. Related: [Environment.GetFolderPath(…CommonApplicationData) is still returning “C:\Documents and Settings\” on Vista](https://stackoverflow.com/a/38491499/150605) – Lance U. Matthews Mar 14 '21 at 00:12
  • You can check under `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders` and `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders` (and the same two keys under `SOFTWARE\WOW6432Node`) to make sure everything looks as it should. – Lance U. Matthews Mar 14 '21 at 00:31
  • The registrery entries look correct. This is what I have in my code: GetPhoto.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures); And it puts me in my personal pictures folder, not public. – Charles Banks Mar 14 '21 at 05:09
  • What does `Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures);` return? just do a debug-printline on what that returns. I guarantee it will print out `C:\Users\Public\Pictures`. So it's not that call. It's something else. – Andy Mar 14 '21 at 06:26
  • Check [this out](https://social.msdn.microsoft.com/Forums/vstudio/en-US/b7559bbe-fc4f-4554-a9b6-ef72d181f7d1/openfiledialog-will-not-show-initaldirectoryquotcuserspublicpublic-documentsquot?forum=csharpgeneral). Someone else having the same issue back in 2015. It seems to be a permissions issue of sorts. The OS is blocking you from setting the initial directory to a public directory. – Andy Mar 14 '21 at 06:33

1 Answers1

0

Thank you Andy for your link. None of my research indicated the need to point to a subfolder after the initial SpecialFolder. This works beautifully is actually what I wanted. Since there were no examples found I did not think you could add anything after naming the special folder and never thought to try it.

Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures) + "\Scanned"