public static string GetMimeTypeFromExtension(string extension)
{
string mimeType = string.Empty;
RegistryKey key;
object value;
if (!string.IsNullOrEmpty(extension))
{
if (!extension.StartsWith("."))
{
extension = "." + extension;
}
key = Registry.ClassesRoot.OpenSubKey(extension, false);
value = key != null ? key.GetValue("Content Type", null) : null;
mimeType = value != null ? value.ToString() : string.Empty;
}
return mimeType;
}
While calling you can pass the parameter like," .pdf "
Or
" pdf "
our code will handle the dot !.
No comments:
Post a Comment