The component cannot be found. (Exception from HRESULT: 0x88982F50) UWP

2

I got this error when trying to pick a folder then displaying all the images in it. my code:

 var folderPicker = new Windows.Storage.Pickers.FolderPicker();
            folderPicker.FileTypeFilter.Add(".jpg");
            var folder = await folderPicker.PickSingleFolderAsync();
            var filesList = await folder.GetFilesAsync();
            for (int i = 0; i < filesList.Count ; i++)
            {
                using (var stream = await filesList[i].OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmapImage.SetSourceAsync(stream);
                    Image m = new Image();
                    m.Source = bitmapImage;
                    sp1.Children.Add(m);
                }

            }

it does work when the folder has 4 or 5 images, but more than that i get this error. any help?

c#
uwp
asked on Stack Overflow Sep 15, 2016 by user3159792

1 Answer

3

The problem is probably not in the number of images you are displaying, but in the fact, that you are trying to display a file that is not an image.

In the top of your code you are applying a filter to only ".jpg" images, but this filter applies only to what is displayed in the folder picker dialog, not to what the GetFilesAsync method returns. This means your filesList contains all the files in the folder not only images. To fix this, you can create a filter using the CreateFileQueryWithOptions method first:

 var filesList =
    await folder.CreateFileQueryWithOptions(
          new QueryOptions( CommonFileQuery.DefaultQuery,
                            new string[] {".jpg"} )
       ).GetFilesAsync();

You can try see my sample app with this solution on my GitHub.

answered on Stack Overflow Sep 15, 2016 by Martin Zikmund

User contributions licensed under CC BY-SA 3.0