none
[UWP][C#]FileOpenPicker on windows 10 Mobile -> error

    Question

  • I want do an uwp app where I want use FileOpenPicker but the app work only on windows 10 and not on windows 10 mobile

    On windows 10 mobile my app crash...and the exception message is: "Element not found. (Exception from HRESULT: 0x80070490)"

    This is my code:

            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
    
            StorageFile file = await openPicker.PickSingleFileAsync();
    
            if (file != null)
    
            {
    
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
    
                var image = new BitmapImage();
    
                ImageBrush ib = new ImageBrush();
                ib.ImageSource = image;
    
                image.SetSource(stream);
    
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                var filePath = file.Path;
                localSettings.Values["monimage"] = filePath;
    
                set.Background = new ImageBrush { ImageSource = image, Stretch = Stretch.UniformToFill };
    
            }
    
            else
    
            {
    
                //
    
            }

    I tested my app on Windows 10 mobile 10.0.14393.693


    Sunday, January 15, 2017 3:33 AM

Answers

  • In my case it's not a problem of double tap, but thank you for your help

    Edit: I solved my problem by reinstalling windows 10 mobile on my phone...

    • Edited by Sami54 Tuesday, January 17, 2017 1:13 AM
    • Marked as answer by Sami54 Tuesday, January 17, 2017 1:13 AM
    Monday, January 16, 2017 12:57 AM

All replies

  • Hello Sami54,

    It seems your code has no problem. The error may be caused due to too large size of the picture that you had chosen in OpenPicker. Try using thumbnail's sream instead of the original stream, to control the size.

        //var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
    
        var thumbnail = await file.GetThumbnailAsync(
            Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 
            1024 // Max 1024px
        );
        var stream = thumbnail.AsStreamForRead().AsRandomAccessStream();

    Sunday, January 15, 2017 4:34 AM
  • But the problem is the error happen before I can select a file...
    Sunday, January 15, 2017 5:17 PM
  • Hi!

    I had the same problem.

    I think the issue is when the user double clicks on the open button. I think you can only show 1 file picker at a time. So if you get a double click, the app might try to show 2 of them and that will cause an exception. A simple flag that is set when you open a file picker should do it.

    Therefore, I saw in many articles that the FileOpenPicker on Windows 10 Mobile has a lot issues.

    Hope it wil be useful.

    If it's good for you, can you mark this answer as answer of your question please?

    Follow me on twitter : https://twitter.com/NordineMhoumadi


    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread. SVP utiliser le Marquer comme reponse; sur les reponses qui vous aide car cela permet aux personnes qui peuvent rencontrer le meme probleme que vous, de retrouver rapidement quelle est la reponse qui a resolu leur probleme. De plus, cela encourage aussi la personne qui a repondu a votre question, et de repondre aux suivantes...


    Sunday, January 15, 2017 7:02 PM
  • In my case it's not a problem of double tap, but thank you for your help

    Edit: I solved my problem by reinstalling windows 10 mobile on my phone...

    • Edited by Sami54 Tuesday, January 17, 2017 1:13 AM
    • Marked as answer by Sami54 Tuesday, January 17, 2017 1:13 AM
    Monday, January 16, 2017 12:57 AM