Microsoft Vistual C# 2008

Page 129

Chapter 6: Building .NET-based Applications with C# 

Environment.GetLogicalDrives() returns an array of strings, with each string representing the drive name.  Environment.Version returns an object of type System.Version which contains the detailed information about the current version of the common language runtime (CLR). The event handler for exit button simply calls the Exit() method of the Environment class to terminate the current process. private void btnExit_Click(object sender, EventArgs e) { Environment.Exit(0); }

Obtaining the paths of various Windows Standard folders – Environment.GetFolderPath() The method Environment.GetFolderPath() can be used to get the complete paths of various windows standard folders on the current machine. The only argument passed to the method is a value from the System.Environment.SpecialFolder enumeration. Some of the more common members of this enumeration are: Member ProgramFiles CommonProgramFiles DesktopDirectory Favorites History Personal Programs Recent SendTo StartMenu Startup System ApplicationData CommonApplicationData LocalApplicationData Cookies

Description The program files folder where programs are usually installed The Common Files folder of Program Files. The folder representing the desktop of user The Favorites folder to store favorite links The History folder to store history files The My Documents folder The folder representing the Programs menu of Start Menu The Recent folder The Send To folder The Start menu folder Folder of the Startup menu on the Start>>Programs menu The System folder of Windows folder The Application Data folder The Common Application Data folder The Local Application Data folder The folder used to store cookies setting

private void btnGo_Click(object sender, EventArgs e) { OperatingSystem os = Environment.OSVersion; PlatformID OSid = os.Platform; string[] drives = Environment.GetLogicalDrives(); string drivesString = ""; foreach (string drive in drives) { drivesString += drive + ", "; } lbx.Items.Add("Program Files: \t" + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFil es)); lbx.Items.Add("Common Program Files:\t" + Environment.GetFolderPath (Environment.SpecialFolder.CommonProgramFiles)); lbx.Items.Add("Windows Desktop: \t" + Environment.GetFolderPath (Environment.SpecialFolder.DesktopDirectory)); lbx.Items.Add("Favorites: \t" +

Lecturer: Chhieng Sokha | Nguon Bunsour

125


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.