The Own Clickonce creates extensions, but you can also create a key in the registry to associate a file extension to your 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();
}
Ai, 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.
and what have you done? What error are you encountering?
– Ricardo
then @Ricardo , nothing... intended to start there, but maybe exporting this file as a folder to another directory is a viable option. but would like to be able to export and import that folder, to open on another pc, for example.
– vhoyer
It seems to me that the main question is the association of the file with the program. In this case, if the OP has affinity with English, it has this excellent answer in the Stack Overflow: http://stackoverflow.com/questions/1387769/create-registry-entry-to-associate-file-extension-with-application-in-c would be great for the community.
– Pablo Almeida
@Pablo just a note, it is good to remember that in Windows 10 changed the way of dealing with file associations. Apparently this was not covered in the given question. For earlier versions, it seems sufficient.
– Bacco
@Bacco But even for Win32 applications?
– Pablo Almeida
start with the "create your own extension file"
– vhoyer
@Pablo yes, with the 10 MS does not want the program to override by its own window, but by a standard OS window, at the end of the installation
– Bacco
@Bacco Sacked. It seems that the work to answer this question will be even greater. =/
– Pablo Almeida
@vhoyer when saving the file, you can use the extension you want. This does not change anything. The problem is to associate this extension with your program, which is Pablo’s appointment. By clicking on the program, once associated, your program will receive the file name as if your program had been called: "programaDoVhoier.exe meuarquivo.rmt". I think you should focus the question on the association.
– Bacco
well then, first it would have to open a compressed file like zip, but with another extension name?
– vhoyer
@vhoyer your program already compact and unzip the desired format? This would be a 4th problem :) - Remember that you should ask separate questions for each part of the problem, otherwise it gets complicated. This site is not a forum, but a site of objective questions that receive objective answers. And you can ask one question at a time, and ask new questions at will, as you solve each step. As long as the questions fit the format of the site, you can do several.
– Bacco
I understand, sorry if I had not understood the format of the site right... I will try not to post this kind of thing anymore, so for now, I would have a suggestion to fix this question? and not yet, because when I started thinking about it I came to the stack, but for everything I read before asking the question, it’s relatively easy to compress and unpack, so it wouldn’t be a "problem"
– vhoyer
@Bacco then I think I’ll remove the question and create others, thanks for the help and sorry for the inconvenience...
– vhoyer
@vhoyer took the liberty of editing your question by focusing on the association of the files, but if you don’t like how it looks, you can click here and choose the Revert option in its previous version (5) to discard the changes.
– Bacco
No, thanks @Bacco I was going to try to edit, but you went faster
– vhoyer
@vhoyer feel free to edit over and leave with your words if you feel it necessary. I only tried to leave a single problem in the question, even to make it easier for those who answer. And the good news is, with separate questions, the answers can not only help you, but can be found more easily by others with the same problem. And being separated, people with different knowledge can help better in the parts that dominate.
– Bacco