OpenFileDialog: bug with MultiSelect=true, not all filenames are in the FileNames array

When I select multiple files using the code below, not all files are being entered in the FileNames array correctly. This is most likely due to a fixed length array of some sorts (?). This is especially the case with deeply nested folders. I run into this problem when the combined number of characters of the files exceeds about 750.

Note: this is different from but may be related to how that was fixed by @JohnM

protected Result RunCommand(RhinoDoc doc, RunMode mode)
  OpenFileDialog fd = new OpenFileDialog
    Title = "Select files to apply grids to",
    DefaultExt = "3dm",
    MultiSelect = true,
    Filter = "Rhino 3D Models (.3dm)|*.3dm"
  if (fd.ShowOpenDialog())
    foreach (var f in fd.FileNames)

  return Result.Success;

Hi @menno,

Yes I can see that.

ā€“ Dale

1 Like

Rhino.UI.OpenFileDialog wraps the MFC CFileDialog which has a _MAX_PATH limit on the file name list. This discussion talks about the limitation and ways to increase it. Iā€™m in the process of testing a fix that will ensure the OpenFileDialog.FileNames can contain 100 or more names but there is a character limit, see my notes in RH-50086.

@dale Pointed me at some COM code which allows you to enumerate the file list without using the file buffer which seems to work pretty well. This should get rid of the buffer size limitation.