Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with SaveAsync #503

Closed
ghost opened this issue Mar 23, 2017 · 4 comments
Closed

Issue with SaveAsync #503

ghost opened this issue Mar 23, 2017 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Mar 23, 2017

Hi all,
I have a UWP Desktop application in which I have a page with a CanvasControl. I have the following method:

public async void SaveImage()
{
//CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasDevice device = Canvas1.Device;

        var picker = new FileSavePicker();
        picker.FileTypeChoices.Add("Jpegs", new List<string>() { ".jpg" });

        var file = await picker.PickSaveFileAsync();
        if (file == null)
            return;

        using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
        {
            var renderTarget = new CanvasRenderTarget(device, (float)Canvas1.ActualWidth, (float)Canvas1.ActualHeight, 96);
            await renderTarget.SaveAsync(file.Path, CanvasBitmapFileFormat.Jpeg);                
        }
    }

which raise an exception when the "SaveAsync" is called:
System.UnauthorizedAccessException: "Zugriff verweigert (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

Access denied basically.

Any Suggestion?

@shawnhar
Copy link
Member

You need to pass the stream directly into SaveAsync, not just the path as a string.

@ghost
Copy link
Author

ghost commented Mar 23, 2017

Hi Shawn,
thanks for your prompt Feedback! I'm a bit confused because I see that this methods is expecting in sequence the filename and the file Format:

image

@shawnhar
Copy link
Member

Look at the other overloads of SaveAsync.

@13thsymphony
Copy link
Member

In general you can't pass around paths in the user's filesystem (as opposed to special folders like the app package directory) because of the UWP security model:
https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions

@shawnhar shawnhar closed this as completed Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants