本文翻译自:Get MIME type from filename extension
如何从文件扩展名中获取MIME类型?
#1楼
参考:https://stackoom.com/question/4Jsi/从文件扩展名获取MIME类型
#2楼
You can find that information in the registry. 您可以在注册表中找到该信息。 For instance, the MIME type for .pdf file can be found in the key HKEY_CLASSES_ROOT\\.pdf
, in the value "Content Type" : 例如,.pdf文件的MIME类型可以在密钥HKEY_CLASSES_ROOT\\.pdf
中找到,值为“内容类型”:
string mimeType = Registry.GetValue(@"HKEY_CLASSES_ROOT\.pdf", "Content Type", null) as string;
#3楼
You could use the table provided from Apache 's httpd. 你可以使用Apache的httpd提供的表。 It should be trivial to map this into a function, dictionary, list, etc. 将它映射到函数,字典,列表等应该是微不足道的。
Also, as seen here , extension->mime type is not necessarily a function. 此外,由于看到