Search code examples
c#uwpfilepicker

UWP Multi File Picker To list


Im trying to Create a Playlist for my Media Application Im very new to this and i've not much of any idea as to how to do this, But the idea is to use to multiPicker function to safe to the storagefile to create a list then add then to my list box(A.k.a) Playlist.. My issue is that fileList.AddRange(pickedFileList); says its not set to an instance of an object im either being really stupid or i just dont understand this if anyone could help. Im a little lost Thanks!

List<StorageFile> fileList;

private async void pick_Click_1(object sender, RoutedEventArgs e)



    {

        var fop = new FileOpenPicker();
        fop.FileTypeFilter.Add(".mp3");
        fop.FileTypeFilter.Add(".mp4");
        fop.FileTypeFilter.Add(".avi");
        fop.FileTypeFilter.Add(".wmv");
        fop.ViewMode = PickerViewMode.List; ;

        IReadOnlyList<StorageFile> pickedFileList;

        pickedFileList = await fop.PickMultipleFilesAsync();
      //Should there be an Existing list here? and if so how do i do that!
        fileList.AddRange(pickedFileList);


        // I'm not sure if i want fileList or pickedFileList here:
        foreach (StorageFile file in pickedFileList)
        {
            Playlist.Items.Add(file.Name);
            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            videoMediaElement.SetSource(stream, file.ContentType);
        }
        videoMediaElement.Play();

Playlist Is my List box in the Xaml im trying to fill


Solution

  • You have to initialize that fileList before you start using it.

    like this:

    List<StorageFile> fileList = new List<StorageFile>();
    

    then it will work.