Async File Save Await does not "Await"

本文关键字:Await quot not does File Save Async | 更新日期: 2023-09-27 17:50:22

如果这是一个骗局,我道歉。我找不到任何专门针对我的问题的东西。我试图保存一个文件使用"等待SaveAsync"。我得到这个错误访问被拒绝。(来自HRESULT的异常:0x80070005 (E_ACCESSDENIED))我认为这是因为它试图在操作完成之前继续移动…但是我用了await,它就不能等等吗?

我的代码

try
        {
            if (CurrentFile == null || !_existingDocument)
            {
                await _generateDoc();
                return;
            }
            var docGen = new CustDocument(_inputs);
            docGen.Save(CurrentFile);
        }
        catch (Exception ex)
        {
            throw;
        }

和我的方法

 private async Task<StorageFile> _generateDoc()
    {
        var docGen = new CustDocument(_inputs);
        var savePicker = new FileSavePicker();
        savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        savePicker.FileTypeChoices.Add("dptx File", new List<string>() {".dptx"});
        savePicker.SuggestedFileName = _inputs.CustomerName.Replace(" ", "").Trim();
        var file = await savePicker.PickSaveFileAsync(); // Error here
        docGen.Save(file);
        return file;
    }

Stack Track (Not Much)

   at Windows.Storage.Pickers.FileSavePicker.PickSaveFileAsync()

在MdTool.ViewModel.RmViewModel灵活;_generateDoc> d__6.MoveNext ()

Async File Save Await does not "Await"

找到了!在这里使用FileSavePicker与MessageDialog's iuiccommand事件

绝不会想到它与对话框有关。致所有回应的人……谢谢你的帮助