2
namespace Silverstone.Manticore.Core
9
/// Summary description for MIMEService.
11
public class MIMEService
14
/// Retrieves the extension associated with the specified content type
15
/// by looking up the type in the Windows Registry.
17
/// <param name="aMIMEType">content-type to retrieve extension for</param>
18
/// <returns>string containing the extension (".foo") associated with the type</returns>
19
public static string GetExtensionForMIMEType(string aMIMEType)
21
RegistryKey clsRoot = Registry.ClassesRoot;
22
string extFromMIMEDBKey = "MIME\\Database\\Content Type\\" + aMIMEType;
23
RegistryKey extensionKey = clsRoot.OpenSubKey(extFromMIMEDBKey);
24
return extensionKey.GetValue("Extension") as String;
28
/// Retrieves the pretty user-readable description of the type by
29
/// looking up the type in the Windows Registry. If no data is found,
30
/// the extension is capitalized and appended with "file", e.g.
33
/// <param name="aMIMEType">content-type to retrieve description for</param>
34
/// <returns>string containing pretty user-readable description of type</returns>
35
public static string GetDescriptionForMIMEType(string aMIMEType)
37
RegistryKey clsRoot = Registry.ClassesRoot;
38
string extension = GetExtensionForMIMEType(aMIMEType);
39
RegistryKey handlerKey = clsRoot.OpenSubKey(extension);
40
string handler = handlerKey.GetValue("") as String;
41
RegistryKey descriptionKey = clsRoot.OpenSubKey(handler);
42
string description = descriptionKey.GetValue("") as String;
43
if (description == "")
44
description = extension.Substring(1,extension.Length-1).ToUpper() + " file";