I'm trying to open a file or choose a directory where to save my file in the documents directory but I get an error.
The following error occurs:
System.Runtime.InteropServices.COMException
HResult=0x80004005
Message=Unspecified error
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
The code:
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()
I get the error when using the OpenPicker
I've tried with both the:
<Capabilities>
<uap:Capability Name="documentsLibrary" />
</Capabilities>`
as well as this:
<Package
...
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp uap5 rescap">
...
<Capabilities>
<rescap:Capability Name="broadFileSystemAccess" />
</Capabilities>`
First, about this code openPicker.PickMultipleFilesAsync(), it will return IReadOnlyList type instead of StorageFile. It means multiple selections instead of single selection.
Second, if you want to use FileOpenPicker, you need to set the types of file you want to choose and set SuggestedStartLocation to a start location appropriate for the type of file being picked. For more information, you can refer this document, but it is about C#.
The following code takes .txt file and PictureLibrary as an example.
Dim localFolder As StorageFile
Dim openPicker As Pickers.FileOpenPicker = New Pickers.FileOpenPicker()
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
openPicker.FileTypeFilter.Add(".txt")
localFolder = Await openPicker.PickSingleFileAsync()
If you want to use documentsLibrary
or broadFileSystemAccess
capability, please check permissions after app installation: Settings -> Privacy -> Documents
or File system
page.
For the first run you should prompt user about that.
User contributions licensed under CC BY-SA 3.0