Damien Doumer
Damien Doumer

Reputation: 2265

Accessing a File in UWP

everyone. I want to access a .wav file from my Assets folder in a UWP app, as follow:

StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(@"ms-appx:///Assets/"+"sound.wav");

but I get the following error:

UWP accessing file System.UnauthorizedAccessException: Access is denied.

I though I did everything right as described in MSDN, but I get the error still.

Upvotes: 2

Views: 943

Answers (1)

A. Milto
A. Milto

Reputation: 2383

Use either

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/"+"sound.wav"));

or

StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\"+"sound.wav");

Upvotes: 1

Related Questions