Archive for the ‘C#’ Category

How To Get List Of Folders?

Posted on the June 20th, 2009 under C#, VB by Administrator

To get a list of all sub directories from one location, you can use GetDirectories method, with code like this:

[ C# ]

string[]  SiteDirectories = 
 System.IO.Directory.GetDirectories(Server.MapPath("~/"));

[ .NET ]

Dim SiteDirectories() As  String = _
 System.IO.Directory.GetDirectories(Server.MapPath("~/"))

Server.MapPath(“~/”) will simply return root folder of application. To build more stable application it is recommended to use try-catch block or to check before if directory exists in your specific case.