472,353 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

sorting files retrieved by OpenFileDialog

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
13 5912
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
"=?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
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
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
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
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
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
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
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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Wim | last post by:
I'm trying to add files with a OpenFileDialog to a listview. This is what I've come up with sofar: protected void ButAddClick(object sender,...
1
by: Olaf Baeyens | last post by:
In .NET v1.1 I am trying to select multiple files using OpenFileDialog like this OpenFileDialog openFileDialog=new OpenFileDialog();...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress =======...
8
by: hugh | last post by:
Hi there, Is there any way to make a DeleteFileDialog that works similar with OpenFileDialog? Thanks very much. Hugh
4
by: Mike | last post by:
I need help understanding why the following code is not working correctly. When run, I can open .mdb files by changing the filter option to "All...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the...
0
by: ebferro | last post by:
Forgive me because this is going to be such a simple question but I'm new and at the foot of the learning curve of VB. I am trying to develop a...
0
by: Gregaz | last post by:
I have a form in my project, which I open as a DialogBox. On that that form there are 3 TextBoxes. To one of them I want to write in a file path....
4
by: jabslim via DotNetMonster.com | last post by:
excuse me, may i ask on how to open files only in drive "e:\" (which is my usb port for flash drives) using openfiledialog? because in the...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.