Select file without using Openfiledialog

Asked

Viewed 566 times

-1

Good, last week I asked this question:

Get path from desktop

At this point, I wanted the program in Load to use the Openfiledialog method, but without the user having to select the file they want, because the file to open would already be implemented in the code. The Code I have is this:

Code

 private void CertificateSigningRequest_Load(object sender, EventArgs e)
    {
        **Abre o ficheiro**
        //string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        //string filePath = Path.Combine(desktop, label1.Text + ".cnf");
        //System.Diagnostics.Process.Start(filePath);

        **Quero apenas que ele selecione o ficheiro, mas não abra**
        openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        openFileDialog1.FileName(label1.Text + ".cnf");
    }

Thank you.

  • 5

    Why do you use OpenFileDialog if the user will not be able to select the file?

  • That’s what I used to wear on a button. Since I now want it on Load, I don’t know how to do it... @Meuchapeu

  • But why use the OpenFileDialog? Will the user be able to choose another file, coming this only as default or always has to be the same file? 'Cause if it’s always the same and you already know his way it makes no sense to use the OpenFileDialog, since despite the name it does not open anything, it just lets the user choose one or more files.

  • And how do I do this @Leandrogodoyrosa? I don’t want to use Openfiledialog anymore, I want the program to get the file right away.

  • In the code you posted the first two lines that are commented already take the file path, which in this case is in the variable filePath, but only with this I have no way of knowing what you should do. What did you do after you took the path with Openfiledialog? From what you said in another comment it seems to me that he was in a Textbox, and after that, how did you use this value? Is there any function you need to call by passing the path? You can post some more code as you were doing?

  • @Leandrogodoyrosa, the openfiledialog, I used to select the file I wanted. Now I want the user not to be able to choose, that is, select what I want, select without opening!

Show 1 more comment

1 answer

0

From what I understand, the code loads a digital certificate using an environment variable (in this case, the variable indicating where the desktop is). The file name is on label1. Therefore, it is not necessary to use the openFileDialog1:

private void CertificateSigningRequest_Load(object sender, EventArgs e)
{
    string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    string filePath = Path.Combine(desktop, label1.Text + ".cnf");
    System.Diagnostics.Process.Start(filePath);
}
  • Amigo @Ciganomorrisonmendez, that code I already have, but that’s opening the file, I don’t want it to open. I just want it to be selected, without the user having to use Openfiledialog. Because when I used Openfiledialog, the path to the file was immediately textbox. I just want the.cnf file to be selected, so that the program runs the code I will have.

  • You want to exhibit in a textbox which certificate the application found, then?

  • Can I talk to you without being around to make it easier?

  • @Godfathersantana has yes. Call me on chat.

Browser other questions tagged

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