Sorting FileNames from OpenFileDialog
Hi
I am using an OpenFileDialog with multi-select. I want to sort the incoming array of strings, i.e. the FileNames member of the OpenFileDialog. So that they are in the same order as displayed in the OpenFileDialog.
Simply transferring FileNames to an ArrayList and sorting does not give the required results.
I was wondering what the ordering rules were for displaying filenames in the OpenFiledialog ?
Any help would be appreciated
cheers
simon
[506 byte] By [
sclement] at [2007-11-20 9:54:15]

# 1 Re: Sorting FileNames from OpenFileDialog
Actually I am not sure what the default sorting of the files are done. But you can easily sort the returned array yourself.
Array.Sort(yourDialog.FileNames);
This will sort the array in alphabetical order.
Laitinen
# 2 Re: Sorting FileNames from OpenFileDialog
Hi Laitinen
Thats my problem. The default sort of my array list, returns the array list in alphabetical order.
The OpenFileDialog, does something different when displaying filenames. I wondered if anybody knew how the filenames were sorted in the OpenFileDialog ?
Cheers
simon
# 3 Re: Sorting FileNames from OpenFileDialog
The Filenames in any Dialog are sorted based on the selection. It can be Name, Size, Type or Modified.
Do you want your filenames to be in the same order as they are shown in FileOpenDialog?
# 4 Re: Sorting FileNames from OpenFileDialog
Hi Shuja
Yes I did want them to be sorted in the same order as they are shown in the OpenFileDialog. It does not seem to be a simple alphabetical sort.
If there are numeric suffixes at the end of the filename, for instance:
frag 1
frag 2
frag 10
They would be displayed in the openfiledialog as above.
What i want to do is sort the FileNames member of the OpenFileDialog, so that the order of strings in the FileNames array is the same as they are displayed in the OpenfileDialog
If the 3 filenames above are in an array. doing a simple sort on that array gives:
frag 1
frag 10
frag 2
Which is obviously not the same as the way they were displayed in the OpenFileDialog
cheers
simon
# 5 Re: Sorting FileNames from OpenFileDialog
Regular sorting in C# is based on Strings. If you want to implement the same type of sorting as in Windows, then you will have to use some alternative. This article ( http://www.codeproject.com/cs/algorithms/csnsort.as) shows how to achieve a Numeric String sorting in C#. Might be helpful for you.