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
相关文章
|
2月前
|
JSON Java 数据格式
使用postMan调试接口出现 Content type ‘multipart/form-data;charset=UTF-8‘ not supported“
本文介绍了使用Postman调试接口时遇到的“Content type ‘multipart/form-data;charset=UTF-8’ not supported”错误,原因是Spring Boot接口默认只接受通过`@RequestBody`注解的请求体,而不支持`multipart/form-data`格式的表单提交。解决方案是在Postman中将请求体格式改为`raw`并选择`JSON`格式提交数据。
使用postMan调试接口出现 Content type ‘multipart/form-data;charset=UTF-8‘ not supported“
|
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]
137 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...]
632 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的解决方案
246 0
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
186 0
Data-Data Objects and Attribute Types| 学习笔记
|
Java
JAVA解决方案:Missing URI template variable ‘customersno‘ for method parameter of type String
解决方案 PathVariable和RequestParam的使用 @PathVariable @RequestParam PathVariable和RequestParam的区别 区别在于一个是用?,一个使用/进行传输数据
340 0
|
JavaScript 前端开发
String templates are not supported by current javaScript version
在idea中使用es6新语法中的反斜杠来定义一段html代码结果时会出现问题,本文带大家解决这些问题。
142 0
String templates are not supported by current javaScript version
No injector for custom defined data type的解决办法
No injector for custom defined data type的解决办法
248 0
No injector for custom defined data type的解决办法
How to enable multiple text type for Product
Created by Jerry Wang, last modified on Oct 31, 2014
127 0
How to enable multiple text type for Product
|
存储 JSON 前端开发
enum的json反序列化问题 415 Unsupported Media Type
enum的反序列过程中如果使用了jackson的注解,很可能会产生一个神奇的bug
632 0
enum的json反序列化问题 415 Unsupported Media Type