lunedì 22 settembre 2008

Retrieve system folder c#

Here you can find a way to retrieve the system folder.
Very simple, call the System.Environment.GetFolderPath with the corrisponding enum System.Environment.SpecialFolder.See the sample below.

private string GetSystemSpecialFolderDirectory()
{
//Program files
string sProgramFilesFolder = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.ProgramFiles);

//Personal
string sPersonalFolder = System.Environment.GetFolderPath (
System.Environment.SpecialFolder.Personal);

//Desktop
string sDesktopFolder = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.DesktopDirectory);

//Application Data
string sApplicationDataFolder = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.ApplicationData);

//System:
string sSystemFolder = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.System);


MessageBox.Show("Program files: " + sProgramFilesFolder +
"\r\nPersonal: " + sPersonalFolder +
"\r\nDesktop: " + sDesktopFolder +
"\r\nApplication Data: " + sApplicationDataFolder +
"\r\nSystem: " + sSystemFolder);
}

Very simple isn't it ?

2 commenti:

FAV ha detto...

Yeah. Very extremely useful.

jurget ha detto...

thanks