1

I work with the CommonOpenFileDialog class from the Windows® API Code Pack for Microsoft® .NET Framework that implements the IFileOpenDialog interface.

More info about Windows API CodePack here: http://archive.msdn.microsoft.com/WindowsAPICodePack

Problem: The below method returns the First selected folder if (multiple folders) or (mutltiple folders and files) were selected in the "Open File Dialog" dialog window.

IFileOpenDialog.GetSelectedItems([MarshalAs(UnmanagedType.Interface)] out IShellItemArray ppsai)

How to return All selected elements (folders and files) in the IFileOpenDialog window as a list of IShellItem, no matter what I selected there?

Murat Korkmaz
  • 1,329
  • 2
  • 19
  • 37

1 Answers1

2

You need to specify the Multiselect property.

Here's an unmarshalled example:

CommonOpenFileDialog folderDialog = new CommonOpenFileDialog("Input Folder Selection");
        folderDialog.IsFolderPicker = true;
        folderDialog.Multiselect = true;

        if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
        {
            foreach (string folderName in folderDialog.FileNames)   //it's a little confusing, but FileNames represents folders as well in the API
            {
                // do something
            }
        }
Ryan Loggerythm
  • 2,877
  • 3
  • 31
  • 39