By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,885 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,885 IT Pros & Developers. It's quick & easy.

sorting files retrieved by OpenFileDialog

P: n/a
I'm not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by default
they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I've searched for an answer but
nothing has come up. Any ideas?
Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
See if the following helps
NOTE: Havent compiled it, so might have typo or syntax errors

' Comparer Class
Public Class CompareFileDates
Implements IComparer
Function IComparer.Compare(ByVal a As Object, ByVal b As Object) As Integer
Return DateTime.Compare( System.Io.File.GetLastWriteTime(DirectCast(a,
String)) , System.Io.File.GetLastWriteTime(DirectCast(b, String)) )
End Function
End Class

' Code to sort the files by date
Array.Sort(files, new CompareFileDates());

HTH
rawCoder

"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I'm not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by default they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I've searched for an answer but
nothing has come up. Any ideas?

Nov 21 '05 #2

P: n/a
"=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
<Ra***********@discussions.microsoft.com> wrote in
news:A1**********************************@microsof t.com:
I'm not happy with the order in which OpenFileDialog retrieves
multiple selected files. I want them in Date order, oldest to newest,
but by default they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is
invert the filename order. I need Date order. I've searched for an
answer but nothing has come up. Any ideas?


I think the anwser would be to create two arrays and add the selected files
to one array as FileInfo(path) and the other array add FileInfo
(path).DateCreated for each item returned, then do [Array].Sort
(dateArray,fileInfoArray), the resulting fileInfoArray will be sorted by
dateArray. More on this here:http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/cpref/html/frlrfsystemarrayclasssorttopic.asp

The other way would be to implement IComparer in a class (which is only one
function) throw all the selected files in an array as FileInfo's and then
[Array].Sort(fileInfoArray,ComparerClass) More info
here:http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp
Nov 21 '05 #3

P: n/a
Thanks for the quick response!

That's foreign functionality to me and I received a number of errors after
inserting the code so I'm obviously going to have to play with it a bit. I
appreciate you getting me started!

Randall

"rawCoder" wrote:
See if the following helps
NOTE: Havent compiled it, so might have typo or syntax errors

' Comparer Class
Public Class CompareFileDates
Implements IComparer
Function IComparer.Compare(ByVal a As Object, ByVal b As Object) As Integer
Return DateTime.Compare( System.Io.File.GetLastWriteTime(DirectCast(a,
String)) , System.Io.File.GetLastWriteTime(DirectCast(b, String)) )
End Function
End Class

' Code to sort the files by date
Array.Sort(files, new CompareFileDates());

HTH
rawCoder

"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I'm not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by

default
they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I've searched for an answer but
nothing has come up. Any ideas?


Nov 21 '05 #4

P: n/a
Thanks, I'll try that as well.

Boggles my mind that MS didn't include a property for this on the
FileOpenDialog.

Randall Arnold

"MeltingPoint" wrote:
"=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
<Ra***********@discussions.microsoft.com> wrote in
news:A1**********************************@microsof t.com:
I'm not happy with the order in which OpenFileDialog retrieves
multiple selected files. I want them in Date order, oldest to newest,
but by default they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is
invert the filename order. I need Date order. I've searched for an
answer but nothing has come up. Any ideas?


I think the anwser would be to create two arrays and add the selected files
to one array as FileInfo(path) and the other array add FileInfo
(path).DateCreated for each item returned, then do [Array].Sort
(dateArray,fileInfoArray), the resulting fileInfoArray will be sorted by
dateArray. More on this here:http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/cpref/html/frlrfsystemarrayclasssorttopic.asp

The other way would be to implement IComparer in a class (which is only one
function) throw all the selected files in an array as FileInfo's and then
[Array].Sort(fileInfoArray,ComparerClass) More info
here:http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp

Nov 21 '05 #5

P: n/a
I would modify RawCoder's code a bit and it might work:

' Comparer Class
Public Class CompareFileDates
Implements IComparer
Function IComparer.Compare(ByVal a As Object, ByVal b As Object) As Integer

Return DateTime.Compare(
DirectCast(System.Io.File.GetLastWriteTime(DirectC ast(a,String)), String)
String)) , DirectCast(System.Io.File.GetLastWriteTime(DirectC ast(b, String))
,string) )
End Function
End Class

' Code to sort the files by date
Array.Sort(files, new CompareFileDates());
"Randall Arnold" wrote:
Thanks for the quick response!

That's foreign functionality to me and I received a number of errors after
inserting the code so I'm obviously going to have to play with it a bit. I
appreciate you getting me started!

Randall

"rawCoder" wrote:
See if the following helps
NOTE: Havent compiled it, so might have typo or syntax errors

' Comparer Class
Public Class CompareFileDates
Implements IComparer
Function IComparer.Compare(ByVal a As Object, ByVal b As Object) As Integer
Return DateTime.Compare( System.Io.File.GetLastWriteTime(DirectCast(a,
String)) , System.Io.File.GetLastWriteTime(DirectCast(b, String)) )
End Function
End Class

' Code to sort the files by date
Array.Sort(files, new CompareFileDates());

HTH
rawCoder

"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I'm not happy with the order in which OpenFileDialog retrieves multiple
selected files. I want them in Date order, oldest to newest, but by

default
they come in by filename, last to first.

The only property that seems relevant is Sort, and all that does is invert
the filename order. I need Date order. I've searched for an answer but
nothing has come up. Any ideas?


Nov 21 '05 #6

P: n/a
That's really saying "Why didn't MS include a property for everything one
could ever think of even if it hasn't been thought of yet.".

The purpose of the FileOpenDialog has been well established for many years.
It is to return 1 or more filenames. It is not to return 1 or more objects
representing information about file(s).

The whole concept of a framework is a foundation upon which you build. MS
have provided the foundation and it's up to you to build upon it to achieve
the desired results. In a nutshell, that's what programming is.
"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
Thanks, I'll try that as well.

Boggles my mind that MS didn't include a property for this on the
FileOpenDialog.

Randall Arnold

"MeltingPoint" wrote:
"=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
<Ra***********@discussions.microsoft.com> wrote in
news:A1**********************************@microsof t.com:
> I'm not happy with the order in which OpenFileDialog retrieves
> multiple selected files. I want them in Date order, oldest to newest,
> but by default they come in by filename, last to first.
>
> The only property that seems relevant is Sort, and all that does is
> invert the filename order. I need Date order. I've searched for an
> answer but nothing has come up. Any ideas?


I think the anwser would be to create two arrays and add the selected
files
to one array as FileInfo(path) and the other array add FileInfo
(path).DateCreated for each item returned, then do [Array].Sort
(dateArray,fileInfoArray), the resulting fileInfoArray will be sorted by
dateArray. More on this
here:http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/cpref/html/frlrfsystemarrayclasssorttopic.asp

The other way would be to implement IComparer in a class (which is only
one
function) throw all the selected files in an array as FileInfo's and then
[Array].Sort(fileInfoArray,ComparerClass) More info
here:http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp

Nov 21 '05 #7

P: n/a
With all due respect, that's a rather disingenuous response. No, my question
was NOT in the manner you allege; I simply asked about ONE property, whch in
no way leads to your hyperbolic sarcasm.

And while the functionality of the dialog control may have remained static
for many years, that's not a reason for it to always remain that way. I note
that the .NET framework both added to and took away from many controls.
Obviously MS doesn't consider the property set to be cast in stone. In my
*opinion* (which is just as valid as yours, by the way), the functionality I
wished for would be easy enough for MS to implement and would simplify what
is obviously a cumbersome workaround; note that none of the suggestions
mentioned here has worked for my purposes.

If you don't have anything productive to contribute to my queries or
comments, I ask you just not add anything at all. Thanks.

"Stephany Young" wrote:
That's really saying "Why didn't MS include a property for everything one
could ever think of even if it hasn't been thought of yet.".

The purpose of the FileOpenDialog has been well established for many years.
It is to return 1 or more filenames. It is not to return 1 or more objects
representing information about file(s).

The whole concept of a framework is a foundation upon which you build. MS
have provided the foundation and it's up to you to build upon it to achieve
the desired results. In a nutshell, that's what programming is.
"Randall Arnold" <Ra***********@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
Thanks, I'll try that as well.

Boggles my mind that MS didn't include a property for this on the
FileOpenDialog.

Randall Arnold

"MeltingPoint" wrote:
"=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
<Ra***********@discussions.microsoft.com> wrote in
news:A1**********************************@microsof t.com:

> I'm not happy with the order in which OpenFileDialog retrieves
> multiple selected files. I want them in Date order, oldest to newest,
> but by default they come in by filename, last to first.
>
> The only property that seems relevant is Sort, and all that does is
> invert the filename order. I need Date order. I've searched for an
> answer but nothing has come up. Any ideas?

I think the anwser would be to create two arrays and add the selected
files
to one array as FileInfo(path) and the other array add FileInfo
(path).DateCreated for each item returned, then do [Array].Sort
(dateArray,fileInfoArray), the resulting fileInfoArray will be sorted by
dateArray. More on this
here:http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/cpref/html/frlrfsystemarrayclasssorttopic.asp

The other way would be to implement IComparer in a class (which is only
one
function) throw all the selected files in an array as FileInfo's and then
[Array].Sort(fileInfoArray,ComparerClass) More info
here:http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp


Nov 21 '05 #8

P: n/a
This article may help.

http://aspnet.4guysfromrolla.com/art...60403-1.2.aspx

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 21 '05 #9

P: n/a
Thanks Jesse! How ironic--I just recently added that code and it worked
right off the bat.

"Jesse Burgess" wrote:
This article may help.

http://aspnet.4guysfromrolla.com/art...60403-1.2.aspx

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...

Nov 21 '05 #10

P: n/a
Has anyone figured this out yet? I just got Vista and find it horribly
frustrating that I can't open a folder from inside a program and sort by
date...only file name...crazy!

MS must have fixed this by now (XP and all other previous OS versions did
this without a question)

Thx!

Jen in SJ
Mar 21 '08 #11

P: n/a
On Mar 21, 9:07*pm, Jen in SJ <Jen in S...@discussions.microsoft.com>
wrote:
Has anyone figured this out yet? *I just got Vista and find it horribly
frustrating that I can't open a folder from inside a program and sort by
date...only file name...crazy!

MS must have fixed this by now (XP and all other previous OS versions did
this without a question)

Thx!

Jen in SJ
3 year-old topic, Wow...
Mar 21 '08 #12

P: n/a
The open file dialog opens with whatever settings the user last opened that
folder. There should be pulldowns to show Details, List, Icons, etc. And the
user should be able to sort the files by clicking on the column headers.
This is not something you can change programmatically.

RobinS.
GoldMail.com

"Jen in SJ" <Jen in SJ@discussions.microsoft.comwrote in message
news:74**********************************@microsof t.com...
Has anyone figured this out yet? I just got Vista and find it horribly
frustrating that I can't open a folder from inside a program and sort by
date...only file name...crazy!

MS must have fixed this by now (XP and all other previous OS versions did
this without a question)

Thx!

Jen in SJ
Mar 22 '08 #13

P: n/a

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:5b**********************************@e10g2000 prf.googlegroups.com...
On Mar 21, 9:07 pm, Jen in SJ <Jen in S...@discussions.microsoft.com>
wrote:
Has anyone figured this out yet? I just got Vista and find it horribly
frustrating that I can't open a folder from inside a program and sort by
date...only file name...crazy!

MS must have fixed this by now (XP and all other previous OS versions did
this without a question)

Thx!

Jen in SJ
--3 year-old topic, Wow...

And yet, Vista hasn't been out that long. Maybe they were prescient? ;-)

Mar 22 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.