2
private async void lstPlayList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
     await new MessageDialog(lstPlayList.SelectedValue.ToString()).ShowAsync();
     StorageFile mediaFile = await StorageFile.GetFileFromPathAsync(Convert.ToString(lstPlayList.SelectedValue.ToString()));
     var mediaStream = await mediaFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
     PlayerME2.SetSource(mediaStream, mediaFile.FileType);
}

Whats wrong with this code? I m trying to play a media file when the selection changed from the list box. but Getting the error

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

I was set the admin privillage too.

<requestedExecutionLevel level="requireAdministrator" uiAccess="true" />

i am getting the error as:

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

WinRT information: Cannot access the specified file or folder (占퀠0). The item is not in a location that the application has access to (including application data folders, folders that are accessible via capabilities, and persisted items in the StorageApplicationPermissions lists). Verify that the file is not marked with system or hidden file attributes.

Additional information: Access is denied.

If there is a handler for this exception, the program may be safely continued.

anything else i missed?

2 Answers 2

1

Windows Store apps are running in a sandbox and this is why cannot access all files by using a path (e.g. by using a path like C:/test.txt). The WinRT security model prevents you from doing this.

You can only open files from allowed storage locations like ApplicationData.Current.LocalFolder or ApplicationData.Current.RoamingFolder or when the user actively selects a file using the file picker.

You can also specify capabilities so that you can access for example the picture or document library.

If you need to access a file which has been picked by the user and which is "outside the sandbox" use the StorageApplicationPermissions.FutureAccessList property to make the file accessible after app restart.

0

Try this:

You should run your project in administrator mode if you want access to the root directory

Add this to the app manifest:

<requestedExecutionLevel level="requireAdministrator" uiAccess="true"/>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.