c# – 简单的silverlight打开文件对话框错误
发布时间:2020-12-16 01:32:11 所属栏目:百科 来源:网络整理
导读:前段时间我写了一个具有csv导入/导出功能的silverlight用户控件.这一直很好,直到最近我发现它在一个场景中出错.这可能是由于转向Silverlight 3. 错误: 消息:Silverlight 2应用程序中的未处理错误 代码:4004 类别:ManagedRuntimeError 消息:System.Secur
前段时间我写了一个具有csv导入/导出功能的silverlight用户控件.这一直很好,直到最近我发现它在一个场景中出错.这可能是由于转向Silverlight 3.
错误: 代码: private void BrowseFileButton_Click(object sender,RoutedEventArgs e) { if (string.IsNullOrEmpty(lblFileName.Text)) { if (MessageBox.Show("Are you sure you want to change the Import file?","Import",MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } } EnableDisableImportButtons(false); var fileName = OpenImportFileDialog(); lblFileName.Text = fileName ?? string.Empty; EnableDisableImportButtons(true); } private string OpenImportFileDialog() { var dlg = new OpenFileDialog { Filter = "CSV Files (*.csv)|*.csv" }; if (dlg.ShowDialog() ?? false) { using (var reader = dlg.File.OpenText()) { string fileName; //process the file here and store fileName in variable return fileName; } } } 我可以打开一个导入文件,但如果我想更改导入文件,并重新打开文件对话框,则会出错.有谁知道为什么会这样? 解决方法
您在一次用户点击时执行两项操作.
您将显示一个消息框,该消息框有效地使用您的权限来显示用户操作的对话框. 然后尝试显示对话框,因为这是用户操作的第二个对话框,不允许这样做. 摆脱确认对话框,你会没事的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |