NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Manually Creating a Recordset, Part 3

Written by Eric Smith, Northstar Computer Systems LLC

In the past two tips, you've been creating a recordset without the use of a database connection. In this tip, you'll learn what you can do with this recordset once it's created. Note that the code shown here, especially the Sort property, works fine regardless of how the recordset is created. The new code is marked in boldface:
<!-- METADATA TYPE="typelib" FILE="C:\Program files\Common files\System\ado\msado15.dll" --!>
<%
Option Explicit

Dim objFSO     ' As Scripting.FileSystemObject
Dim objFolder  ' As Scripting.Folder
Dim objFile    ' As Scripting.File
Dim rsData     ' As ADODB.Recordset

Set rsData = Server.CreateObject("ADODB.Recordset")
With rsData.Fields
   .Append "Filename", adVarChar, 40, adFldUpdatable
   .Append "Size", adInteger, , adFldUpdatable
End With
rsData.Open , , adOpenDynamic

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath("/"))
For Each objFile in objFolder.Files
   rsData.AddNew
   rsData("Filename") = objFile.Name
   rsData("Size") = objFile.Size
   rsData.Update
Next  ' objFile

rsData.Sort = "Filename"
rsData.MoveFirst
Do Until rsData.EOF
   Response.Write rsData("Filename") _
      & " (" & rsData("Size") & " bytes)
" rsData.MoveNext Loop rsData.Close %>
By setting the Sort property to one of the fields of data, we automatically sort the list of files before we print them out. If, for instance, you wanted to sort the files by size instead of by name, you would use this line instead:
rsData.Sort = "Size"

Keywords: [ Uncategorized ASP Tips ]

Publication Date: 8/9/2000