1

i'm building a project on Xamarin. Right now i have a big issue. I need to browse user's computer for upload any file. He can of course upload multiple files. As i know Xamarin does not provide browsing of all the system but just its. So i tried to find a way with some drag n drop, i didn't find. I tried a filepicker but he let me pick just one file (my client would upload 100 files at once) so it doesn't fit to what i need. Finally i decided to do my own browsing system but it takes forever to browse because of the UI. Do you have any solution for me ? I would appreciate a package with a filepicker that allow multiple files.

Thanks

Philigane
  • 163
  • 1
  • 2
  • 12

1 Answers1

2

Have you tried the class FileOpenPicker in UWP ?

It supports to pick multiple files , check the method FileOpenPicker.PickMultipleFilesAsync.

Sample

  1. Define interface in Forms project

    public interface MyFilePicker
    {
        Task OpenFilePickerAsync();
    }
    
  2. Implement in UWP project

    [assembly: Dependency(typeof(UWPFilePicker))]
    namespace App24.UWP
    {
        class UWPFilePicker : MyFilePicker
        {
            public async Task OpenFilePickerAsync()
            {
                var openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".png");
                IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
                if (files.Count > 0)
                {
                    StringBuilder output = new StringBuilder("Picked files:\n");
                    // Application now has read/write access to the picked file(s)
    
                }
                else
                {
                    return;
                }
            }
        }
    }
    
  3. Call it in Forms project

    private async void Button_Clicked(object sender, EventArgs e)
    {
        MyFilePicker service = DependencyService.Get<MyFilePicker>();
        await service.OpenFilePickerAsync();
    }
    
ColeX
  • 14,062
  • 5
  • 43
  • 240