UWP 未授权异常 [英] UWP UnauthorizedException

查看:13
本文介绍了UWP 未授权异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写我的第一个 UWP 应用程序,只是为了学习技巧.我正在构建一个从下载的 facebook-archive 中提取数据的小应用程序.

I am currently writing my first UWP app just to learn the ropes. I am building a small application that pulls data from downloaded facebook-archive.

但是当我尝试打开文件时(即使每个人都拥有完全访问权限),我收到了 UnauthorizedException.我不明白这一点,我没有发现任何人对任何旧文件都有这个问题(有很多人在更具体的情况下遇到问题,但不仅仅是硬盘上的一个简单文件)

But when I try to open the file (even though everybody has full access) I get an UnauthorizedException. I don't understand this and I haven't found anybody having this problem with just any old file (there are many people having problems with more specific scenarios but not just a simple file on their hard drive)

System.UnauthorizedAccessException was unhandled by user code
  HResult=-2147024891
  Message=Access to the path 'C:UserspatriDownloadsfacebook-100004420950389htmlmessages.htm' is denied.
  Source=System.IO.FileSystem
  StackTrace:
       at System.IO.WinRTIOExtensions.<TranslateWinRTTaskCore>d__1`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.IO.WinRTFileSystem.<OpenAsync>d__1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.IO.WinRTFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
       at System.Xml.XmlSystemPathResolver.GetEntity(Uri uri, String role, Type typeOfObjectToReturn)
       at System.Xml.XmlTextReaderImpl.FinishInitUriString()
       at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
       at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
       at Facebookalyzer.FacebookArchiveParser.PopulateArchiveFromHtml(String filePath, FacebookMessageArchive archive)
       at Facebookalyzer.FacebookArchiveParser.<>c__DisplayClass0_0.<ExtractAllChatMessages>b__0()
       at System.Threading.Tasks.Task.Execute()
  InnerException:

有人知道为什么我会收到此异常吗?或者只是你不应该直接在 UWP-Apps 中访问硬盘驱动器上的文件(这会让我质疑为什么他们提供文件打开对话框如果是这种情况)

Does anybody know why I am getting this exception? Or is it just a fact that you should not access files on your hard drive directly in UWP-Apps (which would make me question though Why they provide a file open dialog if that was the case)

推荐答案

您没有显示您的代码,但听起来您是在尝试按路径打开文件,而不是直接使用文件选择器返回的 StorageFile.

You don't show your code, but it sounds like you are trying to open the file by path rather than directly using the StorageFile returned by the file picker.

您的应用无法直接访问大部分文件系统(包括下载目录),只能通过文件系统代理间接访问此类文件.StorageFile 对象与代理一起打开用户已授权的文件,并提供文件内容流供应用读取和写入.

Your app doesn't have direct access to most of the file system (including the downloads directories) and can access such files only indirectly via the file system broker. The StorageFile object works with the broker to open files the use had authorized and provides a stream of the files contents for the app to read and write to.

请参阅我的博客条目 http://blogs.msdn.com/b/wsdevsol/archive/2012/12/05/stray-from-the-path-stick-to-the-storagefile.aspx

See my blog entry http://blogs.msdn.com/b/wsdevsol/archive/2012/12/05/stray-from-the-path-stick-to-the-storagefile.aspx

这篇关于UWP 未授权异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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