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

2020-07-22  本文已影响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;
}
上一篇下一篇

猜你喜欢

热点阅读