Windows Mime Types

In my Windows service built using C #, I am trying to set mime types based on file extensions, as shown below.

static string GetMimeType(string fileName)
        {
            string mimeType = "application/unknown";
            string ext = Path.GetExtension(fileName).ToLower();

            Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);

            if (regKey != null && regKey.GetValue("Content Type") != null)
                mimeType = regKey.GetValue("Content Type").ToString();

            return mimeType;
        } 

On the production server, we do not have Acrobat or the word installed for obvious reasons. How do I get around this? Is there any other way to set mime types? If not, how can I create these mime types on a production server without installing these programs.

Thanks in advance

+3
source share
1 answer

You can simply create registry entries for these types to read code

  • in regedit go to HKEY_LOCAL_MACHINE \ Software \ Classes (central part of HKCR)
  • right click Classes, New Key - name it .pdf
  • , New String - " ", "/PDF"

, Acrobat, regedit .pdf- script, . : , , , - !

, IIS , , , , , - PDF .

+7

Source: https://habr.com/ru/post/1758780/


All Articles