0 Replies - 194 Views - Last Post: 06 March 2009 - 05:56 PM

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Check if an extension is registered

Posted 06 March 2009 - 05:56 PM

Description: Pass the method the extension you wish to check (i.e; .txt) Need a reference to the Microsoft.Win32 NamespaceSnippet to check and see if the provided extension is registered on the system
/// 
/// method for checking if the specified extension is
/// a registered extension on this system
/// 
/// extension we're checking for
/// 
public bool DoesExtensionExist(ref string ext)
{
    //open the HKEY_CLASSES_ROOT hive
    RegistryKey root = Registry.ClassesRoot;

    try
    {
        //open the subkey for this extension
        RegistryKey key = root.OpenSubKey(ext);

        //check if it's null, if no return false
        if (key == null)
            return false;
    }
    catch (Exception)
    {
        return false;
    }
    return true;
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1