/// <summary> /// Returns a link to the given tilde directory path /// with the filename appended. /// /// 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 the /// directory /// /// If the tilde directory path does not end is a slash /// then its file name component will be removed. /// /// Returns an empty string if an error occurs. /// </summary> /// <param name="context">Web site HttpContext object</param> /// <param name="tildeDirectoryPath">Tilde directory path</param> /// <param name="filename">Target file name</param> public static string MakeDirectoryLink (HttpContext context, string tildeDirectoryPath, string filename) { try { tildeDirectoryPath = HttpContextTools.GetDirectoryPath(tildeDirectoryPath); string directoryPath = HttpContextTools.MakeMergedPath(context, tildeDirectoryPath); if (filename == null) { filename = ""; } StringBuilder builder = new StringBuilder(); builder.Append(HTML_Tools.open_div); builder.Append(HTML_Tools.open_anchor); builder.Append(directoryPath); builder.Append(filename); builder.Append(HTML_Tools.mid_anchor_blank); builder.Append(HTML_Tools.open_code); builder.Append(tildeDirectoryPath); builder.Append(HTML_Tools.shut_code); builder.Append(HTML_Tools.shut_anchor); builder.Append(HTML_Tools.shut_div); return(builder.ToString()); } catch (Exception) { return(""); } }
/// <summary> /// Returns a link to the file view utility for the file with /// the given tilde path. /// /// Returns an empty string if an error occurs. /// </summary> /// <param name="context">Web site HttpContext object</param> /// <param name="tildeFilePath">A file tilde path</param> public static string MakeFileViewLinkMarkup (HttpContext context, string tildeFilePath) { try { if (context == null) { return(""); } if (StringTools.IsTrivial(tildeFilePath)) { return(""); } if (!tildeFilePath.StartsWith(SourceTools.tildeStart)) { return(""); } string filename = HttpContextTools.GetFileName(tildeFilePath); string fileviewPath = HttpContextTools. MakeMergedPath(context, fileviewTildePath); StringBuilder builder = new StringBuilder(); builder.Append(openFileViewMarkup); // Download button builder.Append(Download1); builder.Append(tildeFilePath); builder.Append(Download2); // FileView link builder.Append(HTML_Tools.open_span); builder.Append(HTML_Tools.open_anchor); builder.Append(fileviewPath); builder.Append("?"); builder.Append(tildeFilePath); builder.Append(HTML_Tools.mid_anchor_blank); builder.Append(HTML_Tools.open_code); builder.Append(filename); builder.Append(HTML_Tools.shut_code); builder.Append(HTML_Tools.shut_anchor); builder.Append(HTML_Tools.shut_span); // Data for the file string filePath = context.Server.MapPath(tildeFilePath); FileInfo info = new FileInfo(filePath); // bytes long bytes = info.Length; builder.Append(HTML_Tools.open_span); builder.Append(bytes.ToString()); builder.Append(HTML_Tools.shut_span); // most recent date and time DateTime mostrecent = info.MostRecentTime(); builder.Append(HTML_Tools.open_span); builder.Append(mostrecent.ToYMD()); builder.Append(HTML_Tools.shut_span); builder.Append(HTML_Tools.open_span); builder.Append(mostrecent.ToHMS()); builder.Append(HTML_Tools.shut_span); builder.Append(shutFileViewMarkup); return(builder.ToString()); } catch (Exception) { return(""); } }