Search code examples
c#winformsvisual-studio-expressfileopendialog

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


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!


Solution

  • 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.