OpenFileDialog取绝对路径,比如我的文件在C盘。我选中之后在txt框里现实的路径就是C盘的路径,现在现实的时候项目所在的位置。

解决方案 »

  1.   

    OpenFileDialog有很多属性可以设置,
    请参考MSDN
      

  2.   

    OpenFileDialog ofd = new OpenFileDialog();
      ofd.InitialDirectory = @"C:\";
      ofd.ShowDialog();
      

  3.   


            private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                if (ofd.ShowDialog()==DialogResult.OK)
                {
                    string str = ofd.FileName;
                    str=str.Remove(str.LastIndexOf(@"\")+1);
                    textBox1.Text = str;
                }
            }
      

  4.   

    OpenFileDialog.FileName显示的就是文件的绝对路径
    从硬盘根目录一直选中的文件名
      

  5.   

    OpenFileDialog openDlg = new OpenFileDialog();
    openDlg.FileName;//绝对路径
      

  6.   

    FolderBrowserDialognew DirectoryInfo(cdlg.FileName).Root.FullName
      

  7.   

    Directory.GetDirectoryRoot(cdlg.FileName)