Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to get special folders path (cookies, templates, history etc…….) using “Environment Class” in C# (.net 2.0).

Author: Zunnair
Download Source Code : 872_source.zip

In this article you will learn that how we can get special folders path (cookies, templates, history etc…….) using environment class in C# and VB.

 

Special Folders:
Special folders are those folders which are made by windows. For example cookies, history, templates and many more.
Special Folders Name:
First we have to know that how we can get the name of these special folders. For this purpose environment class provides us an “enumeration” named Special Folders. By using this we can get the names and by using names we can get the path of theses folders.
Folders Name (Enumerations):
Environment.SpecialFolder.ApplicationData;
            Environment.SpecialFolder.CommonApplicationData;
            Environment.SpecialFolder.CommonProgramFiles;
            Environment.SpecialFolder.Cookies;
            Environment.SpecialFolder.Desktop;
            Environment.SpecialFolder.DesktopDirectory;
            Environment.SpecialFolder.Favorites;
            Environment.SpecialFolder.History;
            Environment.SpecialFolder.InternetCache;
            Environment.SpecialFolder.LocalApplicationData;
            Environment.SpecialFolder.MyComputer;
            Environment.SpecialFolder.MyDocuments;
            Environment.SpecialFolder.MyMusic;
            Environment.SpecialFolder.MyPictures;
            Environment.SpecialFolder.Personal;
            Environment.SpecialFolder.ProgramFiles;
            Environment.SpecialFolder.Programs;
            Environment.SpecialFolder.Recent;
            Environment.SpecialFolder.SendTo;
            Environment.SpecialFolder.StartMenu;
            Environment.SpecialFolder.Startup;
            Environment.SpecialFolder.System;
            Environment.SpecialFolder.Templates;
Get Special Folder Path:
To get the path of a special folder by using the enumeration environment class provides us a function named Get Folder Path (). This function takes an enumeration of type Special folder and returns the string. String contains the path of a folder.
To demonstrate make a window application. Drag one text box and one button on the form. Press button you will get the path in text box.
Now write the following code on button click event
C#
private void btn_Path_Click(object sender, EventArgs e)
        {
            string str;
 str = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            txt_Path.Text = str;
        }
VB
Private Sub btn_Path_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String
        str = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        txt_Path.Text = str
    End Sub
This simple code gets the path of special folder.
This code is for getting path of Application data folder which is a special folder. By writing the enumerations which I told you above, you can get path of any special folder.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
 
            this.Text = "Devasp.Net Application";
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
 
        Me.Text = "Devasp.Net Application"
 End Sub
 
This simple article tells how we can get special folders path (cookies, templates, history etc…….) using environment class in C# and VB (.net 2.0).

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Conversion of different data types in Byte, (object to Byte, Boolean byte, Date Time to Byte, string to Byte, etc…..) using “Convert Class” in C# (Conversion PART2).

Disclaimer - Privacy
© 2002-2017 DevASP.net