-1
Good, last week I asked this question:
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.
Why do you use
OpenFileDialog
if the user will not be able to select the file?– MeuChapeu
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
– Don Vito
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 theOpenFileDialog
, since despite the name it does not open anything, it just lets the user choose one or more files.– Leandro Godoy Rosa
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.
– Don Vito
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?– Leandro Godoy Rosa
@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!
– Don Vito