473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 6067
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, System.EventArgs e) { OpenFileDialog MyDialog = new...
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(); openFileDialog.Multiselect=true; i...
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 ======= Development information about the page is as follows 1....
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 Files (*.*)" but while "Access Database (mdb.*)" is...
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 dialog first opens, the filter works correctly, and...
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 Windows application that will present the user with...
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. To have it easier I have an OpenFileDialog control...
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 openfiledialog, even when i set my initialdirectory to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.