Returns the mime type associated with the extension

简介:


/// <summary>

/// Returns the mime type associated with the extension

/// </summary>

/// <param name="extension">Extension of the file type.  Eg. ".pdf"</param>

/// <returns>String.Empty if not found</returns>

public string GetMimeType(string extension)

{

  string mimeType = String.Empty;

 

  // Attempt to get the mime-type from the registry.

  Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension);

  if (regKey != null)

  {

    string type = (string)regKey.GetValue("Content Type");

    if (type != null)

      mimeType = type;

  }

  return mimeType;

}

分类: Code Snippets
http://www.cnblogs.com/hardrock/archive/2005/12/31/309144.html
相关文章
|
4月前
|
JSON Java 数据格式
Could not extract response: no suitable HttpMessageConverter found for ..content type [text/html...]
Could not extract response: no suitable HttpMessageConverter found for ..content type [text/html...]
354 0
|
10月前
|
Java
jstl错误:According to TLD or attribute directive in tag file, attribute value does not accept any expr
jstl错误:According to TLD or attribute directive in tag file, attribute value does not accept any expr
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
JSON 数据格式
UE4 structure and JSON conversion - DTBPJson plugin description
UE4 structure and JSON conversion - DTBPJson plugin description
79 0
|
XML JSON JavaScript
Simple Jsonpath Support
我们在日常开发中,json几乎随处可见,但是繁琐的json,也给我们解析带来了很多烦恼的问题,多层级的解析,以及各种嵌套对象的解析,那有没有一种更简单的解析方式呢?
117 0
Simple Jsonpath Support
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
166 0
Data-Data Objects and Attribute Types| 学习笔记
|
JavaScript 前端开发
String templates are not supported by current javaScript version
在idea中使用es6新语法中的反斜杠来定义一段html代码结果时会出现问题,本文带大家解决这些问题。
136 0
String templates are not supported by current javaScript version
No injector for custom defined data type的解决办法
No injector for custom defined data type的解决办法
242 0
No injector for custom defined data type的解决办法
|
存储 JSON 前端开发
enum的json反序列化问题 415 Unsupported Media Type
enum的反序列过程中如果使用了jackson的注解,很可能会产生一个神奇的bug
612 0
enum的json反序列化问题 415 Unsupported Media Type
How to add extension field to report
How to add extension field to report
121 0