C# Finding Special Folders, My Documents, Home, etc

There are many times you need to find a user's home directory or my documents folder. .NET has made this pretty easy. It's all enumerated in the

Environment.SpecialFolder enumeration

The following values are available are pretty self explanatory, however the link above explains all the details.

Environment.SpecialFolder.ApplicationData
Environment.SpecialFolder.System
Environment.SpecialFolder.CommonApplicationData
Environment.SpecialFolder.CommonProgramFiles
Environment.SpecialFolder.Cookies
Environment.SpecialFolder.Desktop
Environment.SpecialFolder.DesktopDirectory
Environment.SpecialFolder.Favorites
Environment.SpecialFolder.History
Environment.SpecialFolder.InternetCache
Environment.SpecialFolder.LocalApplicationData
Environment.SpecialFolder.MyComputer
Environment.SpecialFolder.MyMusic
Environment.SpecialFolder.MyPictures
Environment.SpecialFolder.Personal
Environment.SpecialFolder.ProgramFiles
Environment.SpecialFolder.Programs
Environment.SpecialFolder.Recent
Environment.SpecialFolder.SendTo
Environment.SpecialFolder.StartMenu


Now to get the actual path stored you have to pass the enumeration you want into the

Environment.GetFolderPath method.

So

string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);


Will load the actual physical path of the desktop directory into our string.

Comments

Popular posts from this blog

String.Replace vs Regex.Replace

C# Producer Consumer using Rabbit MQ

C# Form Application in Kiosk Mode/Fullscreen