Robert MacLean
17 May 2010
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:
- AdminTools
- CDBurning
- CommonAdminTools
- CommonDesktopDirectory
- CommonDocuments
- CommonMusic
- CommonOemLinks
- CommonPictures
- CommonProgramFilesX86
- CommonPrograms
- CommonStartMenu
- CommonStartup
- CommonTemplates
- CommonVideos
- Fonts
- LocalizedResources
- MyVideos
- NetworkShortcuts
- PrinterShortcuts
- ProgramFilesX86
- Resources
- SystemX86
- Templates
- UserProfile
- 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));