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
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts