Entries Tagged 'C#' ↓

How To Get List Of Folders?

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.