获取文件类型 Content Type

C# Code…

20150416 更新:

var mimeType = MimeMapping.GetMimeMapping(filePath);

Ps:从注册表中获取

string ext = ".jpg"; //eg: .zip .png .doc .html 
Microsoft.Win32.RegistryKey rg = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
object obj = rg.GetValue("Content Type");
string contentType = obj != null ? obj.ToString() : string.Empty;
rg.Close();

result: .jpg =>  image/jpeg

已禁用评论。