In my windows service built with C# I am trying to set the mime types based on the 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 don't have Acrobat or word installed for obvious reasons. How do I get around with this? Is there any other way of setting the mime types? If not how do I create those mime types on the production server without having to install those softwares.
Thanks in advance
For detecting MIME-types, use the aptly named "mimetype" command. It has a number of options for formatting the output, it even has an option for backward compatibility to "file". But most of all, it accepts input not only as file, but also via stdin/pipe, so you can avoid temporary files when processing streams.
All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop. org.
A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.
Windows makes it very convenient to associate programs and file type Right click the file and open up properties. From here, under the general tab, you can choose which app opens this specific file type. Hit change, and navigate to your shim. bat.
You can simply create the registry entries for those types for your code to read
or you can find a machine that does have Acrobat installed and then use regedit to export the .pdf key to a registry script you can import on your server. You'll end up with lots of scripts: you can use notepad to edit them together but make sure you don't change the encoding when you save - it has to be Unicode!
You could equally add a list of mappings into your application but IIS won't serve static content when it doesn't have a content type so you should probably add them to your registry too in case you ever need to serve static PDFs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With