Create a "file Open" Dialog Button and Write Out to Text Box

Kevdog777 picture Kevdog777 · Jul 4, 2011 · Viewed 16k times · Source

I am wanting to create a browse (fileOpen Dialog) button to search my local drive and then write out the selected path to a text field.

I am using Visual Studio Express 2010

Any help much appreciated!

Answer

Rishabh picture Rishabh · Jul 4, 2011

You can use the file open dialog

The file open dialog on success returns the path of the file which is selected, you can then use the returned path and show it on the label.

OpenFileDialog ofd = new OpenFileDialog();

if (ofd.ShowDialog() == true)
{
string filePath = ofd.FileName;
string safeFilePath = ofd.SafeFileName;
}

The string will have the file path assign it to the label.