类型'System.UnauthorizedAccessException的“的异常出现在mscorlib.dll,但在用户代码中没有处理 [英] An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

查看:3683
本文介绍了类型'System.UnauthorizedAccessException的“的异常出现在mscorlib.dll,但在用户代码中没有处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

型System.UnauthorizedAccessException的的异常出现在mscorlib.dll,但在用户代码中没有处理

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

我设置管理员privillage太

I was set the admin privillage too.

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



我收到错误的:

i am getting the error as:

型System.UnauthorizedAccessException的的异常出现在mscorlib.dll但在用户代码

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

WinRT的信息:无法访问指定的文件或文件夹(占퀠0)。该项目不在该应用程序可以访问一个位置(包括应用程序数据文件夹,这是通过功能访问的文件夹,并在StorageApplicationPermissions列表中坚持项目)。 。验证该文件没有打上系统或隐藏文件属性。

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.

更多信息:访问被拒绝

如果有这种异常的处理程序,该程序可以安全地继续。

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

什么我错过了吗?

推荐答案

Windows应用商店的应用在一个沙箱中运行,这就是为什么不能使用的路径(例如,通过使用像<$ C $的路径访问所有文件C> C:/test.txt )。该WinRT的安全模型可以防止你这样做。

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.

您可以从允许存储位置只能打开文件,如 ApplicationData.Current.LocalFolder ApplicationData.Current.RoamingFolder 或当用户使用的文件选择器

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.

如果您需要访问已经被用户采摘,这是外沙箱使用的 StorageApplicationPermissions.FutureAccessList 属性,以使应用程序重启后的文件进行访问。

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.

这篇关于类型'System.UnauthorizedAccessException的“的异常出现在mscorlib.dll,但在用户代码中没有处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆