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
相关文章
|
7月前
|
XML 数据格式
Xml declaration should precede all document content
Xml declaration should precede all document content
|
8月前
|
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...]
796 0
使用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
109 0
|
XML JSON JavaScript
Simple Jsonpath Support
我们在日常开发中,json几乎随处可见,但是繁琐的json,也给我们解析带来了很多烦恼的问题,多层级的解析,以及各种嵌套对象的解析,那有没有一种更简单的解析方式呢?
145 0
Simple Jsonpath Support
|
XML Java 数据库连接
Open quote is expected for attribute "{1}" associated with an element type "id".
Open quote is expected for attribute "{1}" associated with an element type "id".
209 0
Open quote is expected for attribute "{1}" associated with an element type "id".
|
存储 JSON 前端开发
enum的json反序列化问题 415 Unsupported Media Type
enum的反序列过程中如果使用了jackson的注解,很可能会产生一个神奇的bug
655 0
enum的json反序列化问题 415 Unsupported Media Type
JakartaEE Struts2 The content of element type "package" must match "(result-types?,interceptors?,...
异常信息: The content of element type "package" must match "(result-types?,interceptors?,default-interceptor- ref?,default-action...
1085 0

热门文章

最新文章