Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UWP未授权异常_C#_.net_Visual Studio_Windows Runtime_Uwp - Fatal编程技术网

C# UWP未授权异常

C# UWP未授权异常,c#,.net,visual-studio,windows-runtime,uwp,C#,.net,Visual Studio,Windows Runtime,Uwp,我目前正在编写我的第一个UWP应用程序,只是为了学习诀窍。我正在构建一个小应用程序,从下载的facebook档案中提取数据 但是当我试图打开文件时(即使每个人都有完全的访问权限),我得到了一个未经授权的异常。我不明白这一点,而且我还没有发现任何人在处理任何旧文件时会遇到这种问题(有很多人在处理更具体的场景时会遇到问题,但不仅仅是硬盘上的一个简单文件) System.UnauthorizedAccessException未由用户代码处理 HResult=-2147024891 Message=对路

我目前正在编写我的第一个UWP应用程序,只是为了学习诀窍。我正在构建一个小应用程序,从下载的facebook档案中提取数据

但是当我试图打开文件时(即使每个人都有完全的访问权限),我得到了一个未经授权的异常。我不明白这一点,而且我还没有发现任何人在处理任何旧文件时会遇到这种问题(有很多人在处理更具体的场景时会遇到问题,但不仅仅是硬盘上的一个简单文件)

System.UnauthorizedAccessException未由用户代码处理
HResult=-2147024891
Message=对路径“C:\Users\patri\Downloads\facebook-10000442950389\html\messages.htm”的访问被拒绝。
Source=System.IO.FileSystem
堆栈跟踪:
在System.IO.WinRTIOExtensions.d_u1`1.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.IO.WinRTFileSystem.d__1.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
打开(字符串完整路径、文件模式、文件访问访问、文件共享、Int32 bufferSize、文件选项、文件流父级)
位于System.IO.FileStream.Init(字符串路径、文件模式、文件访问访问、文件共享、Int32 bufferSize、文件选项)
位于System.Xml.XmlSystemPathResolver.GetEntity(Uri、字符串角色、类型typeOfObjectToReturn)
位于System.Xml.XmlTextReaderImpl.FinishInitUriString()处
位于System.Xml.XmlReaderSettings.CreateReader(字符串inputUri,XmlParserContext inputContext)
位于System.Xml.Linq.XDocument.Load(字符串uri,LoadOptions)
在FaceBookAnalyzer.FacebookArchiveParser.PopulateArchiveFromHtml(字符串文件路径,FacebookMessageArchive存档)
在FaceBookAnalyzer.FacebookArchiveParser.c__DisplayClass0_0.b_0()中
在System.Threading.Tasks.Task.Execute()中
内部异常:

有人知道我为什么会得到这个例外吗?或者只是因为你不应该在UWP应用程序中直接访问硬盘上的文件(这会让我产生疑问,如果是这样的话,为什么它们会提供文件打开对话框)

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

您的应用程序无法直接访问大多数文件系统(包括下载目录),只能通过文件系统代理间接访问这些文件。StorageFile对象与代理一起打开用户授权的文件,并为应用程序提供文件内容流,供其读取和写入


请看我的博客

非常感谢。这正是问题所在。我想我可以像在普通桌面应用程序中一样打开文件!您好,我使用我的app LocalFolder创建文件,但这是未经授权的异常@罗布·卡普兰
System.UnauthorizedAccessException was unhandled by user code
  HResult=-2147024891
  Message=Access to the path 'C:\Users\patri\Downloads\facebook-100004420950389\html\messages.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: