1.OpenFileDialog

 1         private void btnOpen_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog ofd = new OpenFileDialog();
 4             ofd.InitialDirectory = @"C:\Users\LWP1398\Desktop"; //设置初始路径
 5             ofd.Filter = "Excel文件(*.xls)|*.xls|Csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //设置“另存为文件类型”或“文件类型”框中出现的选择内容
 6             ofd.FilterIndex = 2; //设置默认显示文件类型为Csv文件(*.csv)|*.csv
 7             ofd.Title = "打开文件"; //获取或设置文件对话框标题
 8             ofd.RestoreDirectory = true;
 9             if (ofd.ShowDialog() == DialogResult.OK)
10             {
11                 //FileName:所选文件的全路径  SafeFileName:所选的文件名
12                 txtPath.Text = "FileName:" + ofd.FileName + "\r\n" + "SafeFileName:" + ofd.SafeFileName;
13             }
14         }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-09-24
  • 2021-08-15
相关资源
相似解决方案