vhoyer vhoyer - 1 year ago 103
C# Question

How to determine if a file is unknown file type C#

I have the string of the file extension. And I think the question is self explanatory


- unknown to the computer (windows); A file for which there is no default program installed

Answer Source

Directly under HKEY_CLASSES_ROOT in the registry there are a series of keys that are common (and not so common) file extensions.

In the first instance if the extension key doesn't exist then it's truly unknown to the system.

Under each of those keys there can be other keys:

  • PersistentHandler
  • OpenWithList
  • OpenWIthProgIds
  • ShellEx
  • etc.

depending on what type of file it is.

The presence of one (or more) of these keys will tell you whether the system can open the file and what program(s) are installed that can.

You access a registry key via the RegistryKey class

For instance if you call OpenSubKey with the name of the extension it will tell you whether it exists or not by whether the call succeeds or fails. If it succeeds you can then check the subkeys to see what program (if any) can open the file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download