/// <summary> /// Returns the MIME mapping for the specified file name. /// </summary> /// <param name="fileName">The file name that is used to determine the MIME type.</param> /// <returns></returns> public static string GetMimeType(string fileName) { string mimeType = "application/octet-stream"; if (!String.IsNullOrEmpty(fileName)) { // the file name may include the assembly name, truncate it before the comma. int pos = fileName.IndexOf(','); if (pos > -1) { fileName = fileName.Substring(0, pos); } if (!MimeMappings.TryGetValue(Path.GetExtension(fileName), out mimeType)) { mimeType = "application/octet-stream"; } } return(mimeType); }
public ResponseObject(string filename, Stream stream) { Content = stream; ContentType = MimeMappings.TryGetValue(Path.GetExtension(filename), out string mime) ? mime : "application/octet-stream"; }