/// <summary> /// Make the body markup for the AutoImage utility. /// </summary> /// <param name="context">Web site HttpContext object</param> /// <param name="onlyPublic">If true restrict to public subdirectories</param> public static string MakeAutoImageMarkup (HttpContext context, bool onlyPublic) { StringBuilder builder = new StringBuilder(); // path in the file system string directoryPath = FileTools.GetDirectoryPath(context); // path as a tilde web directory path string tildeDirectoryPath = HttpContextTools.GetTildeDirectoryPath(context); List <string> subdirectoryList = HttpContextTools.MakeSubdirectoryList(context, onlyPublic); List <string> imageList = HttpContextTools.MakeFileList(context, FileTools.IMAGE); int M = subdirectoryList.Count; int N = imageList.Count; // create markup builder.Append("\n<p><b>Web Directory: "); builder.Append(tildeDirectoryPath); builder.Append("</b></p>\n"); if (M > 0) { builder.Append("\n<p><b>Subdirectories:</b></p>\n"); MakeSubdirectoryLinks(builder, subdirectoryList); } builder.Append("\n<p><b>Image Count in this Web Directory: "); builder.Append(N); builder.Append("</b></p>\n"); MakeImageLinks(builder, directoryPath, imageList); return(builder.ToString()); }
/// <summary> /// Returns the markup for links to the list of /// subdirectories of the web directory of the context. /// /// Removes subdirectories that begin with "~/app_". /// /// After each subdirectory name in a link, inserts a /// slash and then a reference to the given filename. /// /// The filename may be: /// /// * Empty, so a default servable file will be used. /// /// * A pseudo filename handled by an IHttpHandler. /// /// * Some other filename known to be present in all /// subdirectories. /// /// * Null, which is treated as empty. /// /// If there are no subdirectories, then then the empty /// string will be returned as the markup. /// /// The optional comment heads the list of subdirectory /// names. If omitted, a default comment is constructed. /// </summary> /// <param name="context">Web site HttpContext object</param> /// <param name="filename">The target file name</param> /// <param name="comment">Optional comment to head list</param> /// <param name="onlyPublic">If true restrict to public subdirectories</param> public static string MakeSubdirectoryLinkMarkup (HttpContext context, string filename, string comment, bool onlyPublic) { if (context == null) { return(""); } if (filename == null) { filename = ""; } string tildeDirectoryPath = HttpContextTools.GetTildeDirectoryPath(context); List <string> subnames = HttpContextTools.MakeSubdirectoryList(context, onlyPublic); // Remove names that would lead to paths // that begin with "~/app_". List <string> remove = new List <string>(); foreach (string name in subnames) { string subpath = tildeDirectoryPath + name + "/"; if (!subpath.ToLower().StartsWith("~/app_")) { continue; } remove.Add(name); } foreach (string name in remove) { subnames.Remove(name); } int count = subnames.Count; if (count == 0) { return(""); } StringBuilder builder = new StringBuilder(); builder.Append(HTML_Tools.open_p); if (StringTools.IsTrivial(comment)) { builder.Append("Subdirectories of "); builder.Append(tildeDirectoryPath); builder.Append(" ["); builder.Append(count); builder.Append("]:"); } else { builder.Append(comment); } builder.Append(HTML_Tools.shut_p); foreach (string name in subnames) { string subpath = tildeDirectoryPath + name + "/"; string directorylink = MakeDirectoryLink(context, subpath, filename); builder.Append(directorylink); } return(builder.ToString()); }