文件描述错误的Openfiledialog问题

时间:2019-12-28 11:32:38

标签: c# winforms visual-studio-2015 openfiledialog

Iam使用VS2015-Windows窗体。当我单击浏览按钮时,OpenFileDialog正常运行。但是,假设一旦我在刷新表单数据后重新单击按钮,OpenFileDialog就会挂断。

我不明白我的问题。任何上司都可以指导我吗?

MyFileNameStr = String.Empty;
openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "D:\\";
openFileDialog1.Filter = "(*.xlsx)|*.xls| All files (*.*)|*.*";
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Title = "Select Your Attachment File :- ";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && openFileDialog1.FileName.Length>0) {
    String MyDrawingFile = Path.GetFileName(openFileDialog1.FileName);
    myDataGrid1.CurrentRow.Cells["MyExcel_file"].Value = Path.GetFileName(openFileDialog1.FileName);
    MyFileNameStr = openFileDialog1.SafeFileName.ToString();
    MyFileNameStrs = openFileDialog1.SafeFileName.ToString().Split('_');
}

再次感谢

1 个答案:

答案 0 :(得分:-1)

这是由于 如果单击按钮并浏览文件,则该过程在excel文件上运行。 如果再次单击按钮,则说明该进程正在处理您的excel文件,并且应用程序将挂起。