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

 

 

 

本文转自RubyPdf 的中文博客博客园博客,原文链接  http://www.cnblogs.com/hardrock/archive/2005/12/31/309144.html,如需转载请自行联系原作http://www.cnblogs.com/hardrock/archive/2006/05/17/402654.html

相关文章
|
4月前
|
编译器 C语言
mixing declarations and code is a C99 extension
mixing declarations and code is a C99 extension
177 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...]
647 0
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]
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
186 0
Data-Data Objects and Attribute Types| 学习笔记
|
JavaScript 前端开发
sendData to ABAP backend via multiple form content type
Created by Jerry Wang, last modified on Aug 20, 2014
107 0
sendData to ABAP backend via multiple form content type
Extension spartacussampledata doesnt specify a path and no scanned extension was matching the name
Extension spartacussampledata doesnt specify a path and no scanned extension was matching the name
258 0
Extension spartacussampledata doesnt specify a path and no scanned extension was matching the name
Extension spartacussampledata doesnt specify a path and no scanned extension was matching the name
Extension spartacussampledata doesnt specify a path and no scanned extension was matching the name
Extension spartacussampledata doesnt specify a path and no scanned extension was matching the name
|
存储 JSON 前端开发
enum的json反序列化问题 415 Unsupported Media Type
enum的反序列过程中如果使用了jackson的注解,很可能会产生一个神奇的bug
632 0
enum的json反序列化问题 415 Unsupported Media Type
How to add extension field to report
How to add extension field to report
128 0