Skip to main content

15052010218 Note: This post is part of a series and you can find the rest of the parts in the series index.

Environment.SpecialFolder

If you are building an application which takes advantage of special folders in Windows (special folders are folders like My Documents), you will be happy to know that .NET 4 has expanded the number of special folders it support, by adding 25 new options to the Environment.SpecialFolder enum.

The new options are:

  1. AdminTools
  2. CDBurning
  3. CommonAdminTools
  4. CommonDesktopDirectory
  5. CommonDocuments
  6. CommonMusic
  7. CommonOemLinks
  8. CommonPictures
  9. CommonProgramFilesX86
  10. CommonPrograms
  11. CommonStartMenu
  12. CommonStartup
  13. CommonTemplates
  14. CommonVideos
  15. Fonts
  16. LocalizedResources
  17. MyVideos
  18. NetworkShortcuts
  19. PrinterShortcuts
  20. ProgramFilesX86
  21. Resources
  22. SystemX86
  23. Templates
  24. UserProfile
  25. Windows

Usage is:

Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));

GetFolderPath

The GetFolderPath method has also gotten an update with a new overload which takes a second enum, SpecialFolderOption. This has three values

  • None: Returns the path, but does not verify whether the path exists. If the folder is located on a network, specifying this option can reduce lag time.
  • Create: Verifies the folder path. If the folder does not exist, an empty string is returned. This is the default behavior.
  • DoNotVerify: Forces the folder to be created if it does not already exist.

Super fast network option:

Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos, Environment.SpecialFolderOption.None));