Search code examples
windows-store-appsfileopenpicker

Why is the Documents folder not opened in a Windows Store application?


In the code below the documents folder is not shown to pick a file. The capabilities have been set correctly (I think) otherwise an Exception would be thrown. If I set a breakpoint I see that the code reaches the await statement but then it sits there and nothing happens.

Private Async Function Button_Click_1(sender As Object, e As RoutedEventArgs) As Task
        If ApplicationView.TryUnsnap = False Then
            StatusMessage = "Cannot unsnap."
            Exit Function
        End If
        Dim filePicker As New FileOpenPicker
        filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
        filePicker.ViewMode = PickerViewMode.Thumbnail
        filePicker.FileTypeFilter.Add(".pbn")
        Dim pbnFile = Await filePicker.PickSingleFileAsync
        If pbnFile IsNot Nothing Then
            StatusMessage = pbnFile.Path
        End If
 End Function

EDIT: the first line in the Method above must be:

If ApplicationView.Value = ApplicationViewState.Snapped AndAlso ApplicationView.TryUnsnap = False Then

And the problem is solved...

The XAML:

<Page
    x:Class="HandEditor.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:HandEditor"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Button Click="Button_Click_1">Choose .pbn file</Button>
        <TextBlock Grid.Row="1" Text="{Binding StatusMessage}"/>
    </Grid>
</Page>

Solution

  • This is because your call to unsnap is failing.

    Try snapping your app, then it will work as expected. Remove the exit function part and it works as expected.