其他分享
首页 > 其他分享> > 获取文件路径

获取文件路径

作者:互联网

1.打开单个文件,获取文件名
private void On_Click()
{
  string filename="";

  OpenFileDialog Dialog = new OpenFileDialog();

  Dialog.Filter = "(*.ifc)|";

  if (Dialog.ShowDialog() == DialogResult.OK)
  {
    filename = Path.GetFileNameWithoutExtension(Dialog.FileName);
  }
  else
  {
    MessageBox.Show("未选择");
  }
}


2.打开文件夹,获取文件名路径
private void On_Click()
{
  string[] filepath=null;

  FolderBrowserDialog Dialog = new FolderBrowserDialog();

  Dialog.Description = "";

  if (Dialog.ShowDialog() == DialogResult.OK)
  {
    str = Dialog.SelectedPath;

    filepath = Directory.GetFiles(@str, "*.ifc");
  }
  else
  {
    MessageBox.Show("未选择");
  }
}

3.弹出界面,获取界面选择信息内容
private void On_Click()
{
  Form form = new Form();

  string[] DQ_files = null;

  DialogResult str = form.ShowDialog();

  if (str == DialogResult.OK)
  {
    DQ_files = form.files.Split('@');
  }
  else
  {
    MessageBox.Show("未选择");
  }
}

标签:文件,MessageBox,Dialog,路径,private,DialogResult,获取,str,new
来源: https://www.cnblogs.com/XiaoLang0/p/10794573.html