뒤로 나는 csv 가져 오기/내보내기 기능이있는 실버 라이트 사용자 컨트롤을 작성했습니다. 이것은 잘 작동하고 있으며 최근까지 한 가지 시나리오에서 오류가 있음을 발견했습니다.
메시지 :이 때문에 실버 라이트 3간단한 실버 라이트 파일 열기 대화 상자 오류
에 오류 이동하는되었을 수도 있습니다 실버 라이트 2 응용 프로그램에서 처리되지 않은 오류를
코드 : 4004
카테고리 : ManagedRuntimeError
메시지 : System.Security.SecurityException : 대화 상자는 사용자가 시작해야합니다.
에서 MyControl.OpenImportFileDialog()
에서 System.Windows.Controls.OpenFileDialog.ShowDialog()
에서 ...
코드 :
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;
}
}
}
내가 가져 오기 파일을 열고,하지만 난 가져 오기 파일을 변경하려는 경우, 다시 열려있는 파일 대화 상자를, 그것은 오류가 있습니다. 누구나 이것이 왜 그런지 알 수 있습니까?
또한 dlg.ShowDialog() 호출과 동일한 줄 (또는 이전)에 중단 점을 배치하면이 오류가 나타나기 때문에 디버깅하는 데 문제가 있습니다. 도움을 주시면 감사하겠습니다.
안녕하세요 @ Graeme Bradbury, 나는 똑같은 문제에 직면하고 있지만 SaveFileDialog를 사용하면 대화 상자가 사용자에 의해 시작되어야합니다. 메모리에있는 파일을 다운로드하고 싶습니다. –