Search code examples
c#windowsfileopendialog

openfiledialogue in c# is selecting multiple values but its selecting the last selecteditem as the first


Can anyone guide me as I am facing this issue?

I have a app in which I can bring items through a browse button, now when a user selects multiple files , though it selects them and add them (because multiselect = true) but it is selecting the last selected item at the top why?

Therefore causing the flow to be wrong.


Solution

  • Without seeing the relevant code, the issue could be a different one, but just to make you aware, there are two ways of getting the output: either using FileName, or FileNames.

    If you enable MultiSelect yet only look at the FileName property, you will only get the name of one file,

    This property can only be the name of one selected file. If you want to return an array containing the names of all selected files in a multiple-selection dialog box, use FileNames.

    Well, two ways is a simplification really, because you also have SafeFileName and SafeFileNames. I'll leave the research into such as an exercise for the reader.

    It's possible I have misinterpreted your problem based on comments, but let's see.