Link to home
Start Free TrialLog in
Avatar of amoos
amoos

asked on

How to alphabitize documents produced by asp script??

i have a asp script that produces documents uploaded to a server directory and then displayed in a page.  how do i alphabitize these results??  code is below

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<%
Dim strFileSize
Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("/misc/"))
For each filefound in MyFiles.files
      If filefound.Name <> "default.asp" then
%>
            <a href="/misc/<%= filefound.Name %>"><%= filefound.Name %></a><br />
      <%
      End if
Next
%>
</body>
</html>
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

I haven't had a chance to test it but the modified code below should sort alphabetically.  Let me know how it works or if you have a question about anything I did.
bol

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
<%
Dim strFileSize 
Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("/misc/"))
 
Dim objRSFiles
Set objRSFiles = Server.CreateObject("ADODB.Recordset")
objRSFiles.Fields.Append "FileName", adVarChar, 255
objRSFiles.Open
 
For each filefound in MyFiles.files
      If filefound.Name <> "default.asp" then
 
	    objRSFiles.AddNew
	    objRSFiles.Fields("FileName").Value = filefound.Name
	    objRSFiles.Update
      End if
Next
 
objRSFiles.Sort = "FileName ASC"          ' Change this
objRSFiles.MoveFirst
Do While NOT objRSFiles.EOF
%>
            <a href="/misc/<%= objRSFiles("FileName") %>"><%= objRSFiles("FileName") %></a><br />
      <%
	objRSFiles.MoveNext
Loop
objRSFiles.Close
objRSFiles = Nothing
MyDirectory = Nothing
%>
</body>
</html>

Open in new window

Avatar of amoos
amoos

ASKER

great thank you.  i ran it and below is the error i get

ADODB.Fields error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/misc/default.asp, line 17
Avatar of amoos

ASKER

also i did notice in the script that the below line was in there.  what am i suppose to change it to??  awesome help

objRSFiles.Sort = "FileName ASC"          ' Change this
For the error change line 17 to
objRSFiles.Fields.Append "FileName", 200, 255
The comment in the other line should've been removed.   To save time I copied from some previous questions I helped in.  I didn't remove that comment.
Let me know how it works with this correction or if you have any other questions.
bol
Avatar of amoos

ASKER

awesome, thank you.  ok it ran and showed the documents but below is an error that was displayed.

Microsoft VBScript runtime error '800a005b'

Object variable not set

/misc/default.asp, line 38
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually I realize I may have typoed each line.  Change lines 38 & 39 to ...
Set objRSFiles = Nothing
Set MyDirectory = Nothing
See if that works better first.  That is the proper syntax.
bol
Avatar of amoos

ASKER

brilliant.  truely awesome work.  i removed both lines and bingo it worked with no errors.  thank you so much for all your help
Avatar of amoos

ASKER

awesome help thank you
Your welcome!  I'm glad I could help.  Thanks for another fun question. :)
bol