开发者

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 l开发者_如何学运维ocal drive and then write out the selected path to a text field.

I am using Visual Studio Express 2010

Any help much appreciated!


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.


Assuming your solution is WinForms, and your user is selecting a directory (I'm not sure how to interpret your use of path -- the file's path or a path to a directory), a FolderBrowserDialog might be more appropriate than a OpenFileDialog, as it allows you to choose the folder directly.

Using the FolderBrowserDialog, you can write the SelectedPath propery, which is a string, to your TextBox's .Text property.

If you are trying to determine the path of a specific file, then the OpenFileDialog will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜