AzureBlobFileSystem.AzureBlobStorageProvider.GetContentType C# (CSharp) Метод

GetContentType() приватный Метод

Returns the mime-type of the specified file path, looking into IIS configuration and the Registry
private GetContentType ( string path ) : string
path string
Результат string
        private string GetContentType(string path)
        {
            string extension = Path.GetExtension(path);
            if (String.IsNullOrWhiteSpace(extension))
            {
                return "application/unknown";
            }

            try
            {
                string applicationHost = System.Environment.ExpandEnvironmentVariables(@"%windir%\system32\inetsrv\config\applicationHost.config");
                //string webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/").FilePath;

                // search for custom mime types in web.config and applicationhost.config
                foreach (var configFile in new[] { /*webConfig,*/ applicationHost })
                {
                    if (File.Exists(configFile))
                    {
                        var xdoc = XDocument.Load(configFile);
                        var mimeMap = xdoc.XPathSelectElements("//staticContent/mimeMap[@fileExtension='" + extension + "']").FirstOrDefault();
                        if (mimeMap != null)
                        {
                            var mimeType = mimeMap.Attribute("mimeType");
                            if (mimeType != null)
                            {
                                return mimeType.Value;
                            }
                        }
                    }
                }

                // search into the registry
                RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(extension.ToLower());
                if (regKey != null)
                {
                    var contentType = regKey.GetValue("Content Type");
                    if (contentType != null)
                    {
                        return contentType.ToString();
                    }
                }
            }
            catch
            {
                // if an exception occured return application/unknown
                return "application/unknown";
            }

            return "application/unknown";
        }