![]() |
|
|
|
#1 |
|
I would like to sort the list of files (documents) that I am retrieving into
a DataGrid control when they are first displayed. Currently they just list in the order that they appear in the directory and I would like to sort them on LastWriteTime property. Below is what I am using to populate the DataGrid. Thanks. David Dim dirInfo As New DirectoryInfo(strPathPhy) articleList.DataSource = dirInfo.GetFiles() articleList.DataBind() David C |
|
|
|
|
#2 |
|
Posts: n/a
|
http://morewally.com/cs/blogs/wallym...t-10-2007.aspx Looks like you need to specify the version of the framework if url doesn't meet your need. "David C" <> wrote in message news:... >I would like to sort the list of files (documents) that I am retrieving >into a DataGrid control when they are first displayed. Currently they just >list in the order that they appear in the directory and I would like to >sort them on LastWriteTime property. Below is what I am using to populate >the DataGrid. Thanks. > > David > > > Dim dirInfo As New DirectoryInfo(strPathPhy) > articleList.DataSource = dirInfo.GetFiles() > articleList.DataBind() > > > sloan |
|
|
|
#3 |
|
Posts: n/a
|
I am running on VS 2005 and .Net 2.0
David "sloan" <> wrote in message news:... > > http://morewally.com/cs/blogs/wallym...t-10-2007.aspx > > Looks like you need to specify the version of the framework if url doesn't > meet your need. > > > > > > "David C" <> wrote in message > news:... >>I would like to sort the list of files (documents) that I am retrieving >>into a DataGrid control when they are first displayed. Currently they >>just list in the order that they appear in the directory and I would like >>to sort them on LastWriteTime property. Below is what I am using to >>populate the DataGrid. Thanks. >> >> David >> >> >> Dim dirInfo As New DirectoryInfo(strPathPhy) >> articleList.DataSource = dirInfo.GetFiles() >> articleList.DataBind() >> >> >> > > David C |
|
|
|
#4 |
|
Posts: n/a
|
On Jul 2, 1:03*pm, "David C" <dlch...@lifetimeinc.com> wrote:
> I would like to sort the list of files (documents) that I am retrieving into > a DataGrid control when they are first displayed. *Currently they just list > in the order that they appear in the directory and I would like to sort them > on LastWriteTime property. *Below is what I am using to populate the > DataGrid. *Thanks. > > David > > * * Dim dirInfo As New DirectoryInfo(strPathPhy) > * * articleList.DataSource = dirInfo.GetFiles() > * * articleList.DataBind() something like this, perhaps: (see at http://www.siccolo.com/Articles/Code...ileDialog.html) ... Dim FileInfoComparer As FileInfoComparer = New FileInfoComparer() Dim FileList() As FileInfo = ParentFolder.GetFiles() Array.Sort(FileList, FileInfoComparer) ... where Public Class FileInfoComparer Implements System.Collections.IComparer Public Function Compare(ByVal objFileInfo1 As Object, ByVal objFileInfo2 As Object) As Integer _ Implements IComparer.Compare Dim FileInfo1 As System.IO.FileInfo = CType(objFileInfo1, System.IO.FileInfo) Dim FileInfo2 As System.IO.FileInfo = CType(objFileInfo2, System.IO.FileInfo) Return String.Compare(FileInfo1.Name, FileInfo2.Name, True) End Function End Class more at http://www.siccolo.com/articles.asp siccolo |
|
|
|
#5 |
|
Posts: n/a
|
I'm assuming you mean a GridView control since I don't see a control on the
Data tab called a DataGrid. If that's the case you can just use the GridView's sort method GridView1.Sort("FieldName", SortDirection) HTH S "David C" <> wrote in message news:... >I would like to sort the list of files (documents) that I am retrieving >into a DataGrid control when they are first displayed. Currently they just >list in the order that they appear in the directory and I would like to >sort them on LastWriteTime property. Below is what I am using to populate >the DataGrid. Thanks. > > David > > > Dim dirInfo As New DirectoryInfo(strPathPhy) > articleList.DataSource = dirInfo.GetFiles() > articleList.DataBind() > > > SAL |
|
|
|
#6 |
|
Posts: n/a
|
Oh, that version. Sorry...
S "Mark Rae [MVP]" <> wrote in message news:... > "SAL" <> wrote in message > news:... > >> I'm assuming you mean a GridView control since I don't see a control on >> the Data tab called a DataGrid. > > http://aspnet.4guysfromrolla.com/articles/040502-1.aspx > > > -- > Mark Rae > ASP.NET MVP > http://www.markrae.net SAL |
|
|
|
#7 |
|
Posts: n/a
|
Hi there,
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim files As FileInfo() = New DirectoryInfo("c:\temp").GetFiles() Array.Sort(Of FileInfo)(files, AddressOf FileInfoComparison) articleList.DataSource = files articleList.DataBind() End If End Sub Private Shared Function FileInfoComparison(ByVal fi1 As FileInfo, ByVal fi2 As FileInfo) As Integer Return Date.Compare(fi1.LastWriteTime, fi2.LastWriteTime) End Function -- Milosz "David C" wrote: > I would like to sort the list of files (documents) that I am retrieving into > a DataGrid control when they are first displayed. Currently they just list > in the order that they appear in the directory and I would like to sort them > on LastWriteTime property. Below is what I am using to populate the > DataGrid. Thanks. > > David > > > Dim dirInfo As New DirectoryInfo(strPathPhy) > articleList.DataSource = dirInfo.GetFiles() > articleList.DataBind() > > > > Milosz Skalecki [MCAD] |
|
|
|
#8 |
|
Posts: n/a
|
Thanks.. but this does not seem to work for me. Produces the images in
a random order. thanks. Imports System.Collections Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Sub Page_Load() Dim pictures As New SortedList Dim filename As String = "" Dim i As Integer Dim files As FileInfo() = New DirectoryInfo("c:\ppp\pictures \").GetFiles() Array.Sort(Of FileInfo)(files, AddressOf FileInfoComparison) For i = 0 To files.Length - 1 filename = files(i).Name.ToLower() If filename.EndsWith(".jpg") Then pictures("pictures/" & filename) = "thumb.aspx? src=pictures/" & filename End If Repeater1.DataSource = pictures Page.DataBind() Next End Sub Private Shared Function FileInfoComparison(ByVal fi1 As FileInfo, ByVal fi2 As FileInfo) As Integer Return Date.Compare(fi1.LastWriteTime, fi2.LastWriteTime) End Function End Class jc |
|
|
|
#9 |
|
Posts: n/a
|
"jc" <> wrote in message news:e78fc297-b4ba-4202-827f-... > Thanks.. but this does not seem to work for me. Produces the images in > a random order. > > thanks. > > Imports System.Collections > Imports System.IO > > Partial Class _Default > Inherits System.Web.UI.Page > > > Sub Page_Load() > > Dim pictures As New SortedList > Dim filename As String = "" > Dim i As Integer > > Dim files As FileInfo() = New DirectoryInfo("c:\ppp\pictures > \").GetFiles() > > Array.Sort(Of FileInfo)(files, AddressOf FileInfoComparison) > > > > > For i = 0 To files.Length - 1 > > filename = files(i).Name.ToLower() > > If filename.EndsWith(".jpg") Then > pictures("pictures/" & filename) = "thumb.aspx? > src=pictures/" & filename > End If > > Repeater1.DataSource = pictures > Page.DataBind() > Next > > > End Sub > > > Private Shared Function FileInfoComparison(ByVal fi1 As FileInfo, > ByVal fi2 As FileInfo) As Integer > Return Date.Compare(fi1.LastWriteTime, fi2.LastWriteTime) > End Function > > > > End Class > > Seems to me that you are sorting the list ok in files but then you are creating a new SortedList which has nothing to do with the sort you did on LastWriteTime. The list is most likely sorted on the keys. LS Lloyd Sheen |
|
|
|
#10 |
|
Posts: n/a
|
> Seems to me that you are sorting the list ok in files but then you are > creating a new SortedList which has nothing to do with the sort you did on > LastWriteTime. *The list is most likely sorted on the keys. How can I loop through files in the new sorted order if not by the index? Any suggestion on fixing the code to do what I want? Thanks. jc |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to get total bytes of all files from directory | AlbertM. | Software | 1 | 08-06-2008 01:27 AM |
| Convert Video files to PSP | ivan | DVD Video | 4 | 06-17-2008 11:16 AM |
| Convert Video files to MP4 for iPod | ivan | DVD Video | 0 | 04-26-2006 08:38 AM |
| Very slow recognising DVD disc | Terry Pinnell | DVD Video | 1 | 03-28-2006 06:53 PM |
| Now I introduce some popular software of multimedia | eightsome@gmail.com | DVD Video | 0 | 03-28-2006 02:29 PM |