O'Reilly logo

Programming C# 4.0 by Jesse Liberty, Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Well-Known Folders

Most operating systems have a bunch of well-known filesystem locations, and Windows is no exception. There are designated folders for things like the current user’s documents, pictures, or desktop; the program files directory where applications are installed; and the system folder.

The .NET Framework provides a class called Environment that provides information about the world our program runs in. Its static method GetFolderPath is the one that interests us right now, because it will return the path of various well-known folders. We pass it one of the Environment.SpecialFolder enumeration values. Example 11-13 retrieves the location of one of the folders in which applications can store per-user data.

Example 11-13. Getting a well-known folder location

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

Table 11-4 lists all of the well-known folders that GetFolderPath can return, and the location they give on the installed copy of Windows 7 (64-bit) belonging to one of the authors.

Table 11-4. Special folders

Enumeration

Example location

Purpose

ApplicationData

C:\Users\mwa\

AppData\Roaming

A place for applications to store their own private information for a particular user; this may be located on a shared server, and available across multiple logins for the same user, on different machines, if the user’s domain policy is configured to do so.

CommonApplicationData

C:\ProgramData

A place for applications to store their own private information ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required