Tuesday, June 18, 2013

Forcing Internet Explorer to Automatically Launch a File Type

This week at work I was asked to get Internet Explorer to automatically launch a custom file type for an application that I am working on. I was able to do this manually with IE8 by clearing a checkbox that asked if I should always be prompted when opening the file type. Unfortunately, I could not find a similar option with IE9, which happens to be our target browser for this project.

Luckily, I stumbled across this post on the Microsoft forums, which provided a key registry entry that can be used to force IE9 to auto launch files of a given type upon download. The details of this entry are buried three pages deep in the responses, but it works like a charm. The registry key in question is this one:
You have to add a DWORD value that is named after the file type for which you want to auto launch downloaded files. The example given was AcroPDF.PDF.1, but I had to provide the key name associated with my file type under HKEY_CLASSES_ROOT (i.e. My.File.Type). After testing out the change manually and ensuring that it worked properly, I added some code to my .NET app to check for the existence of the registry value and create the registry value if it does not exist.

Below is an example of what this code would look like. Note that I am checking for null to see if the registry value is missing altogether.