In my c# windows application, I like to get multiple files with a same order as user select the file in openfiledialog window. I'm getting all the selected file but its order is not correct. Anyone help me to solve this problem.
-
1You should create your own dialogHamid Pourjam– Hamid Pourjam2016-07-12 04:17:14 +00:00Commented Jul 12, 2016 at 4:17
-
What kind of order ? Just sort it with your own method openFileDialog.FileNames, probably that is easier.user6522773– user65227732016-07-12 04:20:15 +00:00Commented Jul 12, 2016 at 4:20
-
If user select first file it should be on index [0] then if user selects second file should be on index[1] ...so on. While assigning the openFileDialog.FileNames to a string array the above order should meet.Muthuraman Sundararaj– Muthuraman Sundararaj2016-07-12 04:28:10 +00:00Commented Jul 12, 2016 at 4:28
-
@dotctor can u suggest me any links or give me a code for creating own dialog that meet my constraintMuthuraman Sundararaj– Muthuraman Sundararaj2016-07-12 11:25:19 +00:00Commented Jul 12, 2016 at 11:25
1 Answer
If you look at the documentation for the underlying control's interface OPENFILENAME, you'll see this comment:
If the user selects more than one file, the lpstrFile buffer returns the path to the current directory followed by the file names of the selected files.
And, other than some comments on the separator characters used for different scenarios, what to do if there's not enough buffer, and some details on legacy 8.3 support, that's it. In other words, the OpenFileDialog doesn't offer any mechanism to bubble up the sort information as the underlying Windows Common Dialog Box doesn't offer anyway to get this information out via a standard interface.
If you must preserve it, you'll need to create your own Form or Dialog to track the selection in order, and honestly you'll probably be better off providing an slightly different UI that allows the user to reorder files after they've selected them, similar to how one can reorder lists on some mobile devices.