<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Asp.Net Team's Weblog &#187; sort</title>
	<atom:link href="http://aspnetteam.wordpress.com/tag/sort/feed/" rel="self" type="application/rss+xml" />
	<link>http://aspnetteam.wordpress.com</link>
	<description>Another ASP.NET Weblog</description>
	<lastBuildDate>Thu, 03 Sep 2009 11:54:33 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='aspnetteam.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/ea6345954410fcd98c45fab481df7cbf?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Asp.Net Team's Weblog &#187; sort</title>
		<link>http://aspnetteam.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aspnetteam.wordpress.com/osd.xml" title="Asp.Net Team&#8217;s Weblog" />
		<item>
		<title>Recursively Browse Directories Using ASP.NET VB</title>
		<link>http://aspnetteam.wordpress.com/2008/11/12/recursively-browse-directories-using-aspnet-vb/</link>
		<comments>http://aspnetteam.wordpress.com/2008/11/12/recursively-browse-directories-using-aspnet-vb/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 19:01:06 +0000</pubDate>
		<dc:creator>Frank Adams</dc:creator>
				<category><![CDATA[ASP.NET VB]]></category>
		<category><![CDATA[Directory]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://aspnetteam.wordpress.com/?p=60</guid>
		<description><![CDATA[I have come across an issue.  I have solved it part of the way.  I needed to display the contents of a directory for the user when they click on a link (a folder).  That wasn&#8217;t too much of a problem.  Now I must also display the &#8216;most recent files&#8217; in a list, but instead of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aspnetteam.wordpress.com&blog=4774049&post=60&subd=aspnetteam&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have come across an issue.  I have solved it part of the way.  I needed to display the contents of a directory for the user when they click on a link (a folder).  That wasn&#8217;t too much of a problem.  Now I must also display the &#8216;most recent files&#8217; in a list, but instead of listing all files all the time, I want to be able to just list the 10 most recent files.  There is my problem.  I have searched the Internet. I have found a way to go through the directories.  I have found a way to display the files in the order I need by using a datagrid and a third function.   I just need to limit how many files are displayed.  There are several functions that will accomplish this.  I will share them with you so they are all in one place.  First we have the originating function call:<br />
<code><br />
Public Sub GetFiles(ByVal path As String)<br />
        If File.Exists(path) Then<br />
            ' This path is a file<br />
            ProcessFile(path, path)<br />
        ElseIf Directory.Exists(path) Then<br />
            ' This path is a directory<br />
            ProcessDirectory(path)<br />
        End If<br />
    End Sub</code></p>
<p>This in turn calls the following 2 functions:<br />
<code><br />
Public Sub ProcessDirectory(ByVal targetDirectory As String)<br />
Dim dirInfo As New DirectoryInfo(targetDirectory)<br />
Dim newfiles() As FileInfo<br />
'need to make this global so file are added in each loop<br />
newfiles = dirInfo.GetFiles()<br />
Dim f As FileInfo<br />
' Process the list of files found in the directory.<br />
'Array.Sort(newfiles, New CompareFileInfoDESC)<br />
For Each f In newfiles<br />
ProcessFile(f.Name, f.DirectoryName)<br />
Next<br />
' Recurse into subdirectories of this directory.<br />
Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)<br />
For Each subdirectory As String In subdirectoryEntries<br />
ProcessDirectory(subdirectory)<br />
Next<br />
End Sub<br />
</code><br />
AND<br />
<code><br />
Public Sub ProcessFile(ByVal path As String, ByVal dirname As String)<br />
Dim fi As New FileInfo(dirname + "\" + path)<br />
Dim filelink As String<br />
If position &lt;= 1 Then<br />
Dim myDataColumn As DataColumn<br />
myDataColumn = New DataColumn()<br />
myDataColumn.DataType = Type.GetType("System.String")<br />
myDataColumn.ColumnName = "Filename"<br />
myfiledt.Columns.Add(myDataColumn)<br />
myDataColumn = New DataColumn()<br />
myDataColumn.DataType = Type.GetType("System.String")<br />
myDataColumn.ColumnName = "Creationtime"<br />
myfiledt.Columns.Add(myDataColumn)<br />
End If<br />
Dim row As DataRow<br />
If Not dirname.EndsWith("_vti_cnf") Then<br />
filelink = "<a>" + fi.Name + "</a><br />"<br />
row("filename") = filelink<br />
row("creationtime") = fi.CreationTime<br />
myfiledt.Rows.Add(row)<br />
position += 1<br />
End If<br />
datagrid1.DataSource = AlphabeticSort(myfiledt, 1)<br />
datagrid1.DataBind()<br />
End Sub<br />
</code></p>
<p>The last function that I use is the sort function for the datatable. I need to sort the files by creationdate. Here is that code:</p>
<p><code><br />
Private Function AlphabeticSort(ByVal dtTable As DataTable, ByVal sortOrder As Integer) As DataTable<br />
Dim columnKey As String = "creationtime"<br />
Dim sortDirection As String = ""<br />
Dim sortFormat As String = "{0} {1}"<br />
Select Case sortOrder<br />
Case 0<br />
sortDirection = "ASC"<br />
Case 1<br />
sortDirection = "DESC"<br />
Case Else<br />
sortDirection = "ASC"<br />
End Select<br />
dtTable.DefaultView.Sort = String.Format(sortFormat, columnKey, sortDirection)<br />
Return dtTable.DefaultView.Table<br />
End Function<br />
</code></p>
<p>When I add all these together I get almost what I need.  Like I said, it lists all files.  I need just the first 10 files to be listed.  Somehow I need to add that functionality into the AlphabeticSort function to return the records I need. I thougt I would share with you what I have so far as it may help you.  Any feedback is appreciated. Thank you. </p>
<p>Oh I almost forgot, you have to include the following lines of code above the<br />
<code>Public Sub Page_load....</code> or nothing will work:<br />
<code><br />
Imports System.IO<br />
Public Sub Page_load.....<br />
Dim position As Integer = 1 ' for Public Sub ProcessFile ()<br />
Dim myfiledt As DataTable = New DataTable()<br />
Dim int As Integer = 0<br />
</code></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aspnetteam.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aspnetteam.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aspnetteam.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aspnetteam.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aspnetteam.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aspnetteam.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aspnetteam.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aspnetteam.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aspnetteam.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aspnetteam.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aspnetteam.wordpress.com&blog=4774049&post=60&subd=aspnetteam&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aspnetteam.wordpress.com/2008/11/12/recursively-browse-directories-using-aspnet-vb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7de40145b3f1678a34b54c67d2c8e44?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Frank</media:title>
		</media:content>
	</item>
	</channel>
</rss>