Home All Groups Group Topic Archive Search About

sorting files retrieved by OpenFileDialog

Author
1 Apr 2005 4:59 PM
Randall Arnold
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?

Author
1 Apr 2005 5:49 PM
rawCoder
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

Show quoteHide quote
"Randall Arnold" <RandallArn***@discussions.microsoft.com> wrote in message
news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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?
Author
1 Apr 2005 6:07 PM
Randall Arnold
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

Show quoteHide quote
"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" <RandallArn***@discussions.microsoft.com> wrote in message
> news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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?
>
>
>
Author
2 Apr 2005 1:05 AM
Dennis
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(DirectCast(a,String)), String)
String)) , DirectCast(System.Io.File.GetLastWriteTime(DirectCast(b, String))
,string) )
End Function
End Class

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


Show quoteHide quote
"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" <RandallArn***@discussions.microsoft.com> wrote in message
> > news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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?
> >
> >
> >
Author
1 Apr 2005 6:05 PM
MeltingPoint
"=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
<RandallArn***@discussions.microsoft.com> wrote in
news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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/default.asp?url=/library/en-
us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp
Author
1 Apr 2005 6:15 PM
Randall Arnold
Thanks, I'll try that as well.

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

Randall Arnold

Show quoteHide quote
"MeltingPoint" wrote:

> "=?Utf-8?B?UmFuZGFsbCBBcm5vbGQ=?="
> <RandallArn***@discussions.microsoft.com> wrote in
> news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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/default.asp?url=/library/en-
> us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp
>
Author
2 Apr 2005 7:08 AM
Stephany Young
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.


Show quoteHide quote
"Randall Arnold" <RandallArn***@discussions.microsoft.com> wrote in message
news:E7465902-40AF-464E-9BC3-573342AF9935@microsoft.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=?="
>> <RandallArn***@discussions.microsoft.com> wrote in
>> news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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/default.asp?url=/library/en-
>> us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp
>>
Author
4 Apr 2005 1:11 PM
Randall Arnold
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.

Show quoteHide quote
"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" <RandallArn***@discussions.microsoft.com> wrote in message
> news:E7465902-40AF-464E-9BC3-573342AF9935@microsoft.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=?="
> >> <RandallArn***@discussions.microsoft.com> wrote in
> >> news:A12E5406-9F66-42D1-80B2-F726EC92EFEC@microsoft.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/default.asp?url=/library/en-
> >> us/cpref/html/frlrfsystemcollectionsicomparerclasstopic.asp
> >>
>
>
>
Author
13 Apr 2005 9:23 PM
jburgess101@hotmail.com
This article may help.

http://aspnet.4guysfromrolla.com/articles/060403-1.2.aspx

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