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
相关文章
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
|
4月前
|
编译器 C语言
mixing declarations and code is a C99 extension
mixing declarations and code is a C99 extension
215 0
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
|
Java
【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
145 0
|
6月前
|
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...]
694 0
|
6月前
Argument of type 'XX' is not assignable to parameter of type 'XX'
Argument of type 'XX' is not assignable to parameter of type 'XX'
131 0
|
JSON 数据格式
Content type ‘multipart/form-data;boundary=------57031299820747271;charset=UTF-8‘ not supported的解决方案
Content type ‘multipart/form-data;boundary=------57031299820747271;charset=UTF-8‘ not supported的解决方案
303 0
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
XML JSON JavaScript
Simple Jsonpath Support
我们在日常开发中,json几乎随处可见,但是繁琐的json,也给我们解析带来了很多烦恼的问题,多层级的解析,以及各种嵌套对象的解析,那有没有一种更简单的解析方式呢?
138 0
Simple Jsonpath Support
|
Java
JAVA解决方案:Missing URI template variable ‘customersno‘ for method parameter of type String
解决方案 PathVariable和RequestParam的使用 @PathVariable @RequestParam PathVariable和RequestParam的区别 区别在于一个是用?,一个使用/进行传输数据
349 0