Open files of a certain extent in my program [closed]

2

I'm doing an application in Visual Studio, with the intention of working with extension files itself ( .rmt , subject to change) and can open it later.

I want the user to double-click the files with this extension, the system opens the file using my application, so that it can process the file as I want.

How can I link this extension to my application?

    
asked by anonymous 24.12.2015 / 20:12

1 answer

1

ClickOnce creates extensions , but you you can also create a key in the registry to associate a file extension with its executable. First, declare this static method:

public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
{
   RegistryKey BaseKey;
   RegistryKey OpenMethod;
   RegistryKey Shell;
   RegistryKey CurrentUser;

   BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
   BaseKey.SetValue("", KeyName);

   OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
   OpenMethod.SetValue("", FileDescription);
   OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
   Shell = OpenMethod.CreateSubKey("Shell");
   Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
   Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
   BaseKey.Close();
   OpenMethod.Close();
   Shell.Close();

   CurrentUser = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ucs");
   CurrentUser = CurrentUser.OpenSubKey("UserChoice", RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
   CurrentUser.SetValue("Progid", KeyName, RegistryValueKind.String);
   CurrentUser.Close();
}

Well, you can programmatically associate your application using this method:

SetAssociation(".rmt", "Nome_da_extensao", Application.ExecutablePath, "Minha extenção .rmt");

I got this response from this link here .

    
24.12.2015 / 21:13