473,397 Members | 2,077 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,397 software developers and data experts.

Sort dirInfo.GetFiles("*.*") collection in DataGrid

Hello all!

I have a small problem: I have an ASP.NET page that displays content of a
folder in a DataGrid (more precisely, it displays Name, Lenth and
CreationDate of the files).
Default sort order is by file Name. Howwever, I would like to sort the
collection by the CreationDate.
How to do it?

I use the following code:

Dim dirInfo As New DirectoryInfo(directoryPath)
Dim FileNo As Integer = dirInfo.GetFiles("*.*").Length
If FileNo > 0 Then
dgFiles.DataSource = dirInfo.GetFiles("*.*")
dgFiles.DataBind()
Else
dgFiles.Visible = False
End If

Thank you very much in advance!
Hrvoje
Nov 19 '05 #1
4 6233
Hi Hrvoje
try to to put ur data in data table and sort it
"Hrvoje Vrbanc" wrote:
Hello all!

I have a small problem: I have an ASP.NET page that displays content of a
folder in a DataGrid (more precisely, it displays Name, Lenth and
CreationDate of the files).
Default sort order is by file Name. Howwever, I would like to sort the
collection by the CreationDate.
How to do it?

I use the following code:

Dim dirInfo As New DirectoryInfo(directoryPath)
Dim FileNo As Integer = dirInfo.GetFiles("*.*").Length
If FileNo > 0 Then
dgFiles.DataSource = dirInfo.GetFiles("*.*")
dgFiles.DataBind()
Else
dgFiles.Visible = False
End If

Thank you very much in advance!
Hrvoje

Nov 19 '05 #2
You can a write a wrapper class that uses DirectoryInfo and implements
IComparable...

--
Thanks,
Yunus Emre ALPÖZEN

"Hrvoje Vrbanc" <hr*****@recro.hr> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hello all!

I have a small problem: I have an ASP.NET page that displays content of a
folder in a DataGrid (more precisely, it displays Name, Lenth and
CreationDate of the files).
Default sort order is by file Name. Howwever, I would like to sort the
collection by the CreationDate.
How to do it?

I use the following code:

Dim dirInfo As New DirectoryInfo(directoryPath)
Dim FileNo As Integer = dirInfo.GetFiles("*.*").Length
If FileNo > 0 Then
dgFiles.DataSource = dirInfo.GetFiles("*.*")
dgFiles.DataBind()
Else
dgFiles.Visible = False
End If

Thank you very much in advance!
Hrvoje

Nov 19 '05 #3
Use arraylist and IComparer. Code below

Private Class FileInfoCreationComparer
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object)
As Integer Implements System.Collections.IComparer.Compare
Dim xFile As FileInfo = CType(x, FileInfo)
Dim yFile As FileInfo = CType(y, FileInfo)
Dim time As TimeSpan =
xFile.CreationTime.Subtract(yFile.CreationTime)
Return time.Minutes
End Function
End Class

''''' Changed data binding implementation. Add the files into a array
list and sort.

Dim dirInfo As New DirectoryInfo(directoryPath)
Dim FileNo As Integer = dirInfo.GetFiles("*.*").Length
If FileNo > 0 Then
''Changed Code'''
Dim files() as FileInfo = dirInfo.GetFiles() ''No need for filter
"*.*" if you are selecting everything
Dim list as new ArrayList (files) ''Add the files array to an
array list
list.Sort (new FileInfoCreationComparer())
dgFiles.DataSource = list ''Bind to the array list
dgFiles.DataBind()
Else
dgFiles.Visible = False
End If
NuTcAsE

Nov 19 '05 #4
Thank you all very much!

Hrvoje
"Hrvoje Vrbanc" <hr*****@recro.hr> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hello all!

I have a small problem: I have an ASP.NET page that displays content of a
folder in a DataGrid (more precisely, it displays Name, Lenth and
CreationDate of the files).
Default sort order is by file Name. Howwever, I would like to sort the
collection by the CreationDate.
How to do it?

I use the following code:

Dim dirInfo As New DirectoryInfo(directoryPath)
Dim FileNo As Integer = dirInfo.GetFiles("*.*").Length
If FileNo > 0 Then
dgFiles.DataSource = dirInfo.GetFiles("*.*")
dgFiles.DataBind()
Else
dgFiles.Visible = False
End If

Thank you very much in advance!
Hrvoje

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Arnaud | last post by:
Hi, I work with php 4.3.4 and I don't understand the way php sort this array for example : <? $array = (-1, 30, "test", true); sort($array); var_dump($array); ?>
2
by: Peter S. Guild | last post by:
Hello, I have a simple routine that uses a dataview to hold information. I need to sort these columns by section and then by desc. No matter what I do the dataview will not sort. What am I...
0
by: Sandy | last post by:
Within my tag: <asp:DataGrid I'm using: AllowSorting="true" and OnSortCommand="Sort_Grid" which referrs to a method in my Codebehind file. (see Sort_Grid below) Since I have...
3
by: taly | last post by:
Hi all how can I make the interface for the user so he can sort datagrid? thanks
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using...
3
by: mahtan | last post by:
Please help I have the problem that when I change the data in a Windows.Forms.DataGrid by a separate thread the following Exception is thrown: ThreadSystem.NullReferenceException in...
1
by: Tim | last post by:
In VB .NET I use datagrid to present information and when clicking on the column header, the entire datagrid is sorted. Besides CLICK, what're the other events associated with this type of action?...
0
by: samir | last post by:
hi i have a datagrid where i display some columns. i want to have some columns from the db and 2 i calculate,i can display it but problem is how to sort the calculated columns. here is what i am...
0
by: KA NMC | last post by:
I have a dataGrid that is populated by SQL table. The Datagrid has two dynamic columns - that I created to for calculations. I want to sort the grid on frmload by one of the dynamic columns is that...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.