/// <summary> /// Returns the list of subdirectories /// in the context web directory. /// </summary> /// <param name="context">Web site HttpContext object</param> /// <param name="onlyPublic">If true restrict to public subdirectories</param> public static List <string> MakeSubdirectoryList (HttpContext context, bool onlyPublic) { List <string> list = new List <string>(); if (context == null) { return(list); } string path = FileTools.GetDirectoryPath(context); DirectoryInfo thisdir = new DirectoryInfo(path); DirectoryInfo[] subdirs = thisdir.GetDirectories(); foreach (DirectoryInfo di in subdirs) { string name = di.Name; if (onlyPublic) { if (!SourceTools.IsPublic(name)) { continue; } } list.Add(name); } return(list); }
/// <summary> /// Helper method to perform recursion to populate list. /// /// The directory path is an absolute path. /// </summary> private static void AbsoluteDirectoryPathListHelper (List <string> list, string directoryPath) { try { // If the next 2 steps do not throw an exception // then we are fine to proceed DirectoryInfo info = new DirectoryInfo(directoryPath); DirectoryInfo[] dirs = info.GetDirectories(); // Put directoryPath into the list list.Add(directoryPath); // Do recursion on the subdirectories foreach (DirectoryInfo subdir in dirs) { string name = subdir.Name; if (!SourceTools.IsPublic(name)) { continue; } string path = subdir.FullName; int n = path.Length; if (path[n - 1] != '\\') { path += '\\'; } AbsoluteDirectoryPathListHelper(list, path); } } catch { } }