美文网首页
C#选择文件或文件夹路径

C#选择文件或文件夹路径

作者: 堆石成山 | 来源:发表于2020-07-22 11:58 被阅读0次

    打开文件路径:

    OpenFileDialog fd = new OpenFileDialog();
    fd.Multiselect = false;
    fd.Title = "Please Select File";
    fd.Filter = "dll文件|*.dll";
    if (fd.ShowDialog() == DialogResult.OK)
    {
      tbPath.Text = fd.FileName;
    }
    

    保存文件路径:

    SaveFileDialog fd = new SaveFileDialog();          
    fd.Title = "保存文件";
    fd.Filter = "xml文件|*.xml";
    if (fd.ShowDialog() == DialogResult.OK)
     {
       tbPath.Text = fd.FileName;
     }
    

    选择文件夹路径:

    FolderBrowserDialog fbd = new FolderBrowserDialog();         
    bd.Description = "请选择文件夹:";        
    if (fbd.ShowDialog() == DialogResult.OK)
    {
         tbPath.Text = fbd.SelectedPath;
    }
    

    相关文章

      网友评论

          本文标题:C#选择文件或文件夹路径

          本文链接:https://www.haomeiwen.com/subject/xkuzkktx.html