У меня проблема при сохранении файла Excel в приложении UWP (шаблон Windows):
Dim excel As ExcelPackage = New ExcelPackage()
excel.Workbook.Worksheets.Add("Worksheet 1")
excel.Workbook.Worksheets.Add("Worksheet 2")
excel.Workbook.Worksheets.Add("Worksheet 3")
Dim excelFile As FileInfo = New FileInfo("test2.xlsx")
OutputTextBlock.Text = excelFile.ToString()
excel.SaveAs(excelFile)
Process.Start(excelFile.ToString())
Ошибки
'System.UnauthorizedAccessException' в System.Private.CoreLib.dll
'System.InvalidOperationException' в EPPlus.dll
Как ее решить?
ОБНОВЛЕНИЕ
Пример пути, который работает при сохранении с использованием FileSavePicker:
OutputTextBlock.Text = ""
Dim savePicker As FileSavePicker = New FileSavePicker()
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
savePicker.FileTypeChoices.Add("Plain Text", New List(Of String)() From {
".txt"
})
savePicker.SuggestedFileName = "New Document"
Dim file As StorageFile = Await savePicker.PickSaveFileAsync()
If file IsNot Nothing Then
CachedFileManager.DeferUpdates(file)
Await FileIO.WriteTextAsync(file, "Example file contents.")
Dim status As FileUpdateStatus = Await CachedFileManager.CompleteUpdatesAsync(file)
If status = FileUpdateStatus.Complete Then
OutputTextBlock.Text = "File " & file.Name & " was saved."
ElseIf status = FileUpdateStatus.CompleteAndRenamed Then
OutputTextBlock.Text = "File " & file.Name & " was renamed and saved."
Else
OutputTextBlock.Text = "File " & file.Name & " couldn't be saved."
End If
Else
OutputTextBlock.Text = "Operation cancelled."
End If