Thursday, 12 April 2012

Beginning .Net : Get Directory Information programmatically using .Net

Some time you want to get directory information like sub directories  , last access time , last write time , Create new directory in to parent directory etc... programmatically using .Net.

You can get this information using "DirectoryInfo" class.
"DirectoryInfo" class available in System.IO Namespace.
There is one GetDirectories() method to get information about this.

Syntax :
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(string strDirectoryPath);

Here strDirectoryPath is relative path of directory for which you want to get information

Here are one example which get all directories information of given directory path
       System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo("c:\\");
       //Here you can also specify path like "c:\\temp\\"   to get information of temp directory
        foreach (System.IO.DirectoryInfo objDirectory in directory.GetDirectories())
            Response.Write("</br>Directory Name : " + objDirectory.Name);
            Response.Write("</br>Last Access Time : " + objDirectory.LastAccessTime);
            Response.Write("</br>Last Write Time : " + objDirectory.LastWriteTime);


  1. I really like your blog and would suggest you to buy your own domain and hosting. You are a good blogger and you should take blogging seriously :)

    pool fence tampa | pool fence tampa bay | pool fence tampa fl | pool fence tampa florida | pool fences tampa

  2. Hi Rahul,
    Thank you for a good advice.
    I have plan for this but this will take some time.