/// <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