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
相关文章
|
3月前
|
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...]
|
5月前
|
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]
|
PHP
tp5 获取文件MIME为application/octet-stream问题
后台管理系统利用excel批量导入用户数据时,其他成员的电脑上上传excel mime-type类application/octet-stream; 无法通过后台验证(后台是校验的mime); 但在我的电脑上可以,百度也没有相关解决方法;
182 0
|
Java
JAVA解决方案:Missing URI template variable ‘customersno‘ for method parameter of type String
解决方案 PathVariable和RequestParam的使用 @PathVariable @RequestParam PathVariable和RequestParam的区别 区别在于一个是用?,一个使用/进行传输数据
241 0
|
JavaScript 前端开发
String templates are not supported by current javaScript version
在idea中使用es6新语法中的反斜杠来定义一段html代码结果时会出现问题,本文带大家解决这些问题。
117 0
String templates are not supported by current javaScript version
How to add extension field to report
How to add extension field to report
106 0
How to enable multiple text type for Product
Created by Jerry Wang, last modified on Oct 31, 2014
105 0
How to enable multiple text type for Product
|
存储 JSON 前端开发
enum的json反序列化问题 415 Unsupported Media Type
enum的反序列过程中如果使用了jackson的注解,很可能会产生一个神奇的bug
567 0
enum的json反序列化问题 415 Unsupported Media Type
|
算法 PHP 数据安全/隐私保护