c#.net中,有一个文本框,一个按扭,点击按扭弹出文件选择对话框,当选择文件后,文本框为选中文件的路径? 谢谢各位大侠。

解决方案 »

  1.   


    //按钮btnDBName
    //文本框 txtDBName
    private void btnDBName_Click(object sender, System.EventArgs e)
    {
    this.openFileDlg = new OpenFileDialog();
    this.openFileDlg.Filter="数据库文件|*.mdb";
    this.openFileDlg.Title ="选择要运行的数据库脚本文件";
    this.openFileDlg.ShowDialog();

    if(this.openFileDlg.FileName.Trim().EndsWith(".mdb"))
    {
                                    //获取文件所在目录的路径
    this.strDBPath = this.openFileDlg.FileName.Trim();
    string dbfileName= Path.GetFileName(strDBPath);//获取文件名称
    strdestfileName += "\\" + dbfileName;//获取完整的代文件的路径
    this.txtDBName.Text = this.strDBPath ;
    }
    else
    {
    MessageBox.Show("请选择正确的数据库文件(*.mdb)!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    }
      

  2.   

     OpenFileDialog _FileShow = new OpenFileDialog();
                if (_FileShow.ShowDialog() == DialogResult.OK)
                {
                    textBox1.Text = new FileInfo(_FileShow.FileName).Directory.FullName;
                }
      

  3.   

    这个msdn的帮助文档里就有,或者你在网上收一下就有一堆。学会用搜索和帮助。
      

  4.   

            private void changeLine_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    lineText.Text = folderBrowserDialog.SelectedPath;
                }
            }添加一个FolderBrowserDialog 控件,这个是可以选择路径        private void changeLine_Click(object sender, EventArgs e)
            {
                OpenFileDialog OpenFileDialog1  = new OpenFileDialog();
                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    lineText.Text = new FileInfo(f1.FileName).Directory.FullName;
                }
            }
    添加一个OpenFileDialog 控件,这个是可以选择文件的
      

  5.   


      我怎么找不到FolderBrowserDialog 控件,添加一个OpenFileDialog 控件啊?我用的是 B/S
      

  6.   

    那就用input的file类型不就行了嘛:
    <input type="file" id="sltFile" runat="server">这个是上传控件,点击“浏览”会弹出一个框,选择文件后,文件的地址就显示在了上传控件里了