示例#1
0
        /// <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);
        }
示例#2
0
 public ResponseObject(string filename, Stream stream)
 {
     Content     = stream;
     ContentType = MimeMappings.TryGetValue(Path.GetExtension(filename), out string mime) ? mime : "application/octet-stream";
 }