HtmlAgilityPack.HtmlWeb.GetExtensionForContentType C# (CSharp) Method

GetExtensionForContentType() public static method

Gets the path extension for a given MIME content type.
public static GetExtensionForContentType ( string contentType, string def ) : string
contentType string The input MIME content type.
def string The default path extension to return if any error occurs.
return string
        public static string GetExtensionForContentType(string contentType, string def)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                return def;
            }
            string ext = "";
            if (!SecurityManager.IsGranted(new RegistryPermission(PermissionState.Unrestricted)))
            {
                if (MimeTypes.ContainsValue(contentType))
                {
                    foreach (KeyValuePair<string, string> pair in MimeTypes)
                        if (pair.Value == contentType)
                            return pair.Value;
                }
                return def;
            }

            if (SecurityManager.IsGranted(new RegistryPermission(PermissionState.Unrestricted)))
            {
                try
                {
                    RegistryKey reg = Registry.ClassesRoot;
                    reg = reg.OpenSubKey(@"MIME\Database\Content Type\" + contentType, false);
                    if (reg != null) ext = (string)reg.GetValue("Extension", def);
                }
                catch (Exception)
                {
                    ext = def;
                }
            }
            return ext;
        }