
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
1100
|
Chapter 20: Toolbox
public static string GetWinDir( )
{
string sysDir = Environment.GetFolderPath(Environment.SpecialFolder.System);
return Path.GetFullPath(sysDir + @"\..");
}
Discussion
There is an enumeration to describe almost every significant operating system folder
(
Environment.SpecialFolder). But for some reason, since the inception of .NET, the
Windows directory has been deemed unacceptably off-limits. This recipe exists for
want of an
Environment.SpecialFolder.Windows value. Another way to get at this
value is to use the
Environment.GetEnvironmentVariable function, passing in "windir"
as the value.
Table 20-3 shows all of the other places in the OS you can get through
Environment.
SpecialFolder
.
Table 20-3. The Environment.SpecialFolder enumeration values
Value Description
ApplicationData Roaming user's application data directory
CommonApplicationData Application data directory for all roaming users
CommonProgramFiles Folder for common application components
Cookies Directory where cookies are stored
Desktop The logical desktop folder
DesktopDirectory The physical desktop folder
Favorites Where favorites are stored on disk
History Internet history items folder
InternetCache Where temporary Internet files are stored
LocalApplicationData Nonroaming user’s application data directory ...