Search Unity

FilePicker UWP

Discussion in 'Windows' started by Timo1102, Aug 6, 2019.

  1. Timo1102

    Timo1102

    Joined:
    Jan 27, 2017
    Posts:
    3
    Hi,
    In my Game I can't open the NativeFile picker. I created a seperate Visual Studio project and followed this tutorial. The main code to open the FilePicker is:
    Code (CSharp):
    1. #if NETFX_CORE
    2.         public async void OpenFilePicker()
    3.         {
    4.             var picker = new Windows.Storage.Pickers.FileOpenPicker();
    5.             picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
    6.             picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
    7.             picker.FileTypeFilter.Add(".png");
    8.  
    9.             var file = await picker.PickSingleFileAsync();
    10.             if (file != null)
    11.             {
    12.                 this.onFileSelected?.Invoke(file.Name);
    13.             }
    14.         }
    15. #endif
    16.     }
    If I build the Project and try to access the FilePicker I got the following error:
    error.png

    I hope someone could help me.
     
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    corvusincvr likes this.
  3. Timo1102

    Timo1102

    Joined:
    Jan 27, 2017
    Posts:
    3
    Thank you very much it's working now.
     
  4. Genji70436

    Genji70436

    Joined:
    Jul 6, 2017
    Posts:
    1
    what is ShowOpenPanel input?
    1. public static string ShowOpenPanel(bool includeFiles, bool includeDirectories)
    2. {
    3. Application.InvokeOnUIThread(async () => {
    4. var filePicker = new FileOpenPicker();
    5. filePicker.FileTypeFilter.Add("*");
    6. var file = await filePicker.PickSingleFileAsync();
    7. }, false);
    8. return string.Empty;
    9. }
     
    corvusincvr likes this.