Extract Content Type of file using its extension

In C# we can use registry to get ContentType of any file using its extenstion.

public static string getMimeType(string sExtension)
string extension = sExtension.ToLower();
RegistryKey key = Registry.ClassesRoot.OpenSubKey(“MIME\\Database\\Content Type”);

foreach (string keyName in key.GetSubKeyNames())
RegistryKey temp = key.OpenSubKey(keyName);
if (extension.Equals(temp.GetValue(“Extension”)))
return keyName;
//no success
return string.Empty;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s