Source code:
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlg=new OpenFileDialog();

if (dlg.ShowDialog() == DialogResult.OK)
{
string strPath = dlg.FileName;
MessageBox.Show(strPath);
}

}

解决方案 »

  1.   

    楼上的方法只可以选择文件,你如果想选择文件夹,窗体需要自己做,有两个控件可以容易的解决问题,DriveListBox,DirListBox
    private void driveListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    this.dirListBox1.Path=this.driveListBox1.Drive;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.filepath=this.dirListBox1.Path;
    } public string FilePath
    {
    get{return this.filepath;}
    set{this.filepath=value;}
    }
    我就是这么做的