Joseph Conaty
Joseph Conaty

Reputation: 67

Async File Save Await does not "Await"

I apologize if this is a dupe. I couldnt find anything that dealt specifically with my issue. Im trying to save a file using "await SaveAsync". I get this error Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) I assume its because it attempted to move on before an action completed... but shouldnt it wait because I used "await"?

Here is my code

try
        {
            if (CurrentFile == null || !_existingDocument)
            {
                await _generateDoc();
                return;
            }

            var docGen = new CustDocument(_inputs);

            docGen.Save(CurrentFile);
        }
        catch (Exception ex)
        {

            throw;
        }

And my method

 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()

at MdTool.ViewModel.RmViewModel.<_generateDoc>d__6.MoveNext()

Upvotes: 2

Views: 890

Answers (1)

Joseph Conaty
Joseph Conaty

Reputation: 67

FOUND IT! Here Using FileSavePicker with MessageDialog's IUICommand event

Would have never thought that it had to do with the dialog box. To all who responded... Thanks for the help

Upvotes: 0

Related Questions