public static string GetMimeTypeString(string filePath) { var mimeTypes = new MimeTypes(); MimeType mimeType; using (var fileStream = new FileStream(filePath, FileMode.Open)) { mimeType = mimeTypes.GetMimeTypeByContent(fileStream); } if (mimeType == null) { mimeType = mimeTypes.GetMimeType(filePath); } if (mimeType == null) { return null; } return mimeType.Name; }
/// <summary> Return a MimeTypes instance.</summary> /// <param name="filepath">is the mime-types definitions xml file. /// </param> /// <returns> A MimeTypes instance for the specified filepath xml file. /// </returns> public static MimeTypes Get(String filepath) { MimeTypes instance; lock (Instances.SyncRoot) { instance = (MimeTypes) Instances[filepath]; if (instance == null) { //instance = new MimeTypes(filepath, null); instance = new MimeTypes(filepath); Instances[filepath] = instance; } } return instance; }