Blog

Practical Approach of Getting Special Folders Path in the Environment Using C#

Posted by Lajapathy Arun Blogs | Files, Directory, IO Apr 28, 2012
In this blog we are going to see, How to get the path of all the Special Folders in the Environment using C#.

In this blog we are going to see, How to get the path of all the Special Folders in the Environment using C#.

Step 1: Used Namespace:

using System.IO;

Step 2: Getting all the Special folders:

string[] specialPaths = Enum.GetNames(typeof(Environment.SpecialFolder));

Step 3: Iterating the Special folders to get paths of special folders:

foreach (string special in specialPaths)

Step 4:  Getting the Special folder Enum by its name:

Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), special);

Step 5: Path of Special Folder:

string path = Environment.GetFolderPath(specialFolder);

Step 6: Displaying the Special Folder path and Name:

Response.Write("<b>" + special + " :</b> " + path + "<br/>");

Code Snippet:

protected void Page_Load(object sender, EventArgs e)

        {

            //Getting all the Special folders

            string[] specialPaths = Enum.GetNames(typeof(Environment.SpecialFolder));

 

            //Iterating the Special folders to get paths of sepcial folders

            foreach (string special in specialPaths)

            {

                //Getting the Special folder enum by its name.

                Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), special);

 

                //Path of Special Folder.

                string path = Environment.GetFolderPath(specialFolder);

 

                //Displaying the Special Folder.

                Response.Write("<b>" + special + " :</b> " + path + "<br/>");

            }

        }

Output of Special Folders path

Desktop : C:\Users\laja\Desktop
Programs : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Personal : C:\Users\laja\Documents
MyDocuments : C:\Users\laja\Documents
Favorites : C:\Users\laja\Favorites
Startup : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Recent : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Recent
SendTo : C:\Users\laja\AppData\Roaming\Microsoft\Windows\SendTo
StartMenu : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Start Menu
MyMusic : C:\Users\laja\Music
MyVideos : C:\Users\laja\Videos
DesktopDirectory : C:\Users\laja\Desktop
MyComputer : 
NetworkShortcuts : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Network Shortcuts
Fonts : C:\Windows\Fonts
Templates : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Templates
CommonStartMenu : C:\ProgramData\Microsoft\Windows\Start Menu
CommonPrograms : C:\ProgramData\Microsoft\Windows\Start Menu\Programs
CommonStartup : C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
CommonDesktopDirectory : C:\Users\Public\Desktop
ApplicationData : C:\Users\laja\AppData\Roaming
PrinterShortcuts : C:\Users\laja\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
LocalApplicationData : C:\Users\laja\AppData\Local
InternetCache : C:\Users\laja\AppData\Local\Microsoft\Windows\Temporary
COMMENT USING
PREMIUM SPONSORS
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.