Automatically open my program c#

Asked

Viewed 300 times

1

Good,

I created a program to convert some file formats. Now in windows, I put by default, that whenever I click 2x on *.csr file open my program. How do I program, whenever the user opens a *.csr file, open my program, and automatically put the path to that file in Openfiledialog? Thank you.

Right now I have a button to open file: CSR or CNF. Then the code I have is this:

 private void button2_Click(object sender, EventArgs e)
    {
        string arquivoCNF = VariaveisGlobais.cnf;
        string arquivoCSR = VariaveisGlobais.csr;


        ExecutarComandoSSL(arquivoCNF, arquivoCSR);

        textBox3.Text = ("");
        button2.Enabled = false;
        button3.Enabled = false;
        button4.Enabled = false;
        return;
    }

 //Variáveis
    public static class VariaveisGlobais
    {
        public static string CNF { get; set; }
        public static string CSR { get; set; }
        public static string cnf { get; set; }
        public static string csr { get; set; }
    } 

What I’m asking is: If the user DOES NOT OPEN the program, but directly opens a CSR or CNF, he runs that code.

  • In your program or in Visualstudio? You have created a program that reads the files?

  • I don’t get it @Guilhermenascimento...

  • Are you creating a software that reads the files or do you want to configure visualstudio? You said "I created a program" to understand that Voce created a program that reads files. csr, so your problem is not with visualstudio but with your program. Perhaps the answer from Onosendai will help you. But what it seems to me is that Voce wants to leave pre selected in Opendialog, however this is not clear yet.

  • @Guilhermenascimento is that same friend. I want you to open the . csr program run the code I have. When my program opens it has a button to open the CSR file and read. What I want is that the person when opening a CSR file (without the program) he opens the program alone and runs the code.

  • Then post what you have done so far, please read this guideline: http://answall.com/help/mcve

  • @Guilhermenascimento edited!

  • There is no way to run the code directly, what will run is the code compiled in an application. You want to create an application that in windows such application is set as default for such extension?

Show 2 more comments

1 answer

0

In Visual Studio:

Project Properties > Publish > Options > File Associations

You will see the following interface:

inserir a descrição da imagem aqui

Enter the desired extension and associated program.

Using the Clickonce publication the installer will create the link between the extension and the program automatically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.