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