The following code was supplied by a kind poster as a solution to a
problem i was having. But it's not quite working. I have commented the
code myself below. Can you please read my comments to make sure what
i've said is correct to check my understanding of what is happening.
Also the problem i have is that the openfiledialog isn't being
displayed when i run the code, does anyone know why?
namespace MyNamespace
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
string file; // create a new string variable
called file.
file = FileOpen(); // call the function FileOpen and
set file equal to the returned value.
}
private string FileOpen() //new function, that
returns a string result.
{
string file = null; //assign local file
variable.
//the following uses IF to execute the ShowDialog method of
openFileDialog1, and
//if when the dialog exits the DialogResult is OK - the
Filename selected is stored
//in the local file variable
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
file = openFileDialog1.FileName;
}
return file; //this passes the value of the local file
variable back to the calling Form1_Load
//method.
}
}
}