Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
File UWP开放文件问题_File_Uwp - Fatal编程技术网

File UWP开放文件问题

File UWP开放文件问题,file,uwp,File,Uwp,我试图打开一个文件或选择一个目录,将文件保存在documents目录中,但出现错误 出现以下错误: System.Runtime.InteropServices.COMException HResult=0x80004005 Message=Unspecified error Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stac

我试图打开一个文件或选择一个目录,将文件保存在documents目录中,但出现错误

出现以下错误:

System.Runtime.InteropServices.COMException
  HResult=0x80004005
  Message=Unspecified error

  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>
System.Runtime.InteropServices.COMException
HResult=0x80004005
消息=未指定的错误
来源=
堆栈跟踪:
守则:

Public Sub New()
        InitializeComponent()

        ' Deferred execution until used. Check https://msdn.microsoft.com/library/dd642331(v=vs.110).aspx for further info on Lazy<T> class.
        _activationService = New Lazy(Of ActivationService)(AddressOf CreateActivationService)
        Dim localFolder As StorageFile

        Dim openPicker As Pickers.FileOpenPicker = New Pickers.FileOpenPicker()
        localFolder = openPicker.PickMultipleFilesAsync()
Public Sub New()
初始化组件()
'延迟执行,直到使用。检查https://msdn.microsoft.com/library/dd642331(v=vs.110)。有关懒惰类的更多信息,请访问aspx。
_activationService=New Lazy(属于activationService)(CreateActivationService的地址)
将localFolder设置为StorageFile
Dim openPicker As Pickers.FileOpenPicker=New Pickers.FileOpenPicker()
localFolder=openPicker.PickMultipleFileAsync()
我在使用OpenPicker时遇到错误

我尝试了以下两种方法:

<Capabilities>
    <uap:Capability Name="documentsLibrary" />
  </Capabilities>`

`
除此之外:

<Package
  ...
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp uap5 rescap">
...
<Capabilities>
    <rescap:Capability Name="broadFileSystemAccess" />
</Capabilities>`

...
`

首先,关于此代码openPicker.pickMultipleFileAsync(),它将返回IReadOnlyList类型而不是StorageFile。它意味着多个选择,而不是单个选择

其次,如果要使用FileOpenPicker,则需要设置要选择的文件类型,并将SuggestedStartLocation设置为适合所拾取文件类型的开始位置。有关更多信息,您可以参考这篇文章,但它是关于C的

下面的代码以.txt文件和PictureLibrary为例

Dim localFolder As StorageFile
Dim openPicker As Pickers.FileOpenPicker = New Pickers.FileOpenPicker()
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
openPicker.FileTypeFilter.Add(".txt")
localFolder = Await openPicker.PickSingleFileAsync()

如果您想使用
documentsLibrary
broadFileSystemAccess
功能,请在安装应用程序后检查权限:设置->隐私->
文档
文件系统
页面


对于第一次运行,您应该向用户提示这一点。

@MaartenDev感谢您修复此帖子!我试了几次都没有成功。