取文件路径

//使用
var filename = OpenfileDlg();

#region 通过路径取文件方法
/// <summary>
/// 通过路径取文件方法
/// </summary>
/// <param name="Defaultpath"></param>
/// <returns></returns>
private static string OpenfileDlg(string Defaultpath = null)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择要打开的文件";
//多选
ofd.Multiselect = true;
//初始目录
ofd.InitialDirectory = Defaultpath;
//设定文件类型
// ofd.Filter = ".bmp|*.bmp|.jpg|*.jpg";

ofd.ShowDialog();

//获得在打开文件对话框中选择的文件的路径
string path = ofd.FileName;
return path;
}
#endregion
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

 

作者:꧁执笔小白꧂