.NET 4 Baby Steps - Part XI: Special folders

15052010218 This post is part of a series—see the rest of the parts in the series index.

Environment.SpecialFolder

If you are building an application that takes advantage of special folders in Windows (e.g., My Documents), you’ll be happy to know that .NET 4 expanded the number of supported special folders with 25 new options in the Environment.SpecialFolder enum:

  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:

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

GetFolderPath Method

The GetFolderPath method has also been updated with a new overload, accepting a second parameter: SpecialFolderOption, which offers three behaviors:

Super-fast network example:

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