DESKTOP

Get the Paths to My Documents, My Pictures, Etc.

9/25/2010 3:21:43 PM
Problem : You need to get the path of a user’s special folders, such as his documents folder.

Solution:
You should never hard-code the paths. Not only can different versions of the OS have different folder names, but the user can change these folders to be in whatever location he wants. Use Environment.GetFolder() with the Environment.SpecialFolder enumeration to retrieve the actual folder on the disk. The following code will print the entire list:


foreach (Environment.SpecialFolder folder in Enum.GetValues(typeof(Environment.SpecialFolder)))
{
string path = Environment.GetFolderPath(folder);
Console.WriteLine("{0}\t==>\t{1}", folder, path);
}

Note

In general, you should put your application’s data in the LocalApplicationData (nonroaming) or ApplicationData (roaming) folder. That is what these folders are meant for. Examine them on your own computer to see how other software uses them. You should never write program data to ProgramFiles or anywhere file security is an issue. The ApplicationData directory will be replicated on all computers to which the user logs on in a domain, so avoid putting unnecessary data there. Starting with Windows Vista, the operating system enforces file security much more strongly, and an application that doesn’t pay attention to security issues can break.


Other  
 
Top 10
HP Spectre XT Touchsmart Review - Everything Is Fine Except Battery Life (Part 2)
HP Spectre XT Touchsmart Review - Everything Is Fine Except Battery Life (Part 1)
Lenovo Thinkpad Carbon Touch Ultrabook Review (Part 3)
Lenovo Thinkpad Carbon Touch Ultrabook Review (Part 2)
Lenovo Thinkpad Carbon Touch Ultrabook Review (Part 1)
Blackberry 10 OS (Part 3)
Blackberry 10 OS (Part 2)
Blackberry 10 OS (Part 1)
How To Keep High-End Speakers In Good Conditions
How To Use TV As An Audio Converter
Most View
Windows Small Business Server 2011 : Managing User Roles
Canon IXUS 510 HS
Review: Nikon D4 – The master of the dark arts (Part 2)
Sharepoint 2007: Use the My Links to Manage Your Links
Every Cloud...(Part 2) - Mobility & Portability
Searching for Google’s future (Part 1) - Taking the tablets
Dell Inspiron 17R Special Edition - Battery Is A Disappointment
10 Valuable TVs For Your Living Room
Silverlight Recipes : Creating Silverlight Using Ruby, Python, or JScript
Build A Home Theatre PC (Part 2)
The Library In Your Pocket (Part 2) - iOS – iPad, Android – Kobo Vox, Kindle Fire, Binatone ReadMe, Google Nexus 7
Samsung 830
Windows 9 : What to expect - 32-bit support , WinRT & XNA
Programming with DirectX : View Transformations
Securing Your Silverlight Application
Programming the Mobile Web : Mobilizing WordPress and Other CMSs
Aerocool Silent Master Blue
Getting Started with Device Manager
Calendar Plus - Simple And Friendly
Transact-SQL in SQL Server 2008 : New date and time Data Types and Functions