Paging through FileSystemObject
alangford | Posted 12:49am 18. July 2002 Server Time |
Is it possible to set up paging using FileSystemObject?
I have this code:
<%
'Create the FileSystemObject object
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Obtain an folder object instance for a particular directory
Dim objFolder
Set objFolder = objFSO.GetFolder("D:Inetpub\ssg\wwwroot\PDFs\")
'Use a For Each ... Next loop to display the files
Dim objFile
Dim currentPage
For Each objFile In objFolder.Files
currentPage = currentPage + 1
Response.Write "<a href='PDFs/"& objFile.Name &"'>" & currentPage & "</a> "
Next
%>
And this code returns 200 pdf files but I only want to show multiples of 10 or 20. Is this possible?
Thanks,
Ashley |
Informant | Posted 3:37pm 18. July 2002 Server Time |
you could do it but you need to loop through it every time you could simple use a counter within a loop to start and stop when you left off perhaps store it in a session variable and then again only displaying the currently selected pdfs. Does that make sense?
Informant | Posted 4:23pm 18. July 2002 Server Time |
Actually I came up with a better way to do it and here is some sample code:
<%
'Create the FileSystemObject object
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Obtain an folder object instance for a particular directory
Dim objFolder
Set objFolder = objFSO.GetFolder("C:\Inetpub\wwwroot\test_docs\")
'Use a For Each ... Next loop to display the files
Dim objFile
Dim currentPage
Dim ArrayOfPDFs()
For Each objFile In objFolder.Files
currentPage = currentPage + 1
Redim Preserve ArrayOfPDFS(currentPage)
ArrayOfPDFS(currentPage) = objFile.Name
Next
Dim Start
Dim StopPoint
Dim MaxSize
MaxSize = Ubound(ArrayOfPDFS)
If Request.QueryString("Start") = "" and Request.QueryString("StopPoint") = "" Then
Start = 0
StopPoint = 10
Else
Start = Request.QueryString("Start") + 10
StopPoint = Request.QueryString("StopPoint") + 10
End if
For i = Start to StopPoint
Response.Write "<a href='PDFs/"& ArrayOfPDFS(i) &"'>" & i & "</a><BR>"
Next
Response.Write "<BR><a href=PageThroughFSO.asp?StopPoint=" & StopPoint & "&Start=" & Start & ">Next</a>"
%>
Informant | Posted 4:25pm 18. July 2002 Server Time |
Now what this code is does not have a Stop Size set I will leave that up to you but will page through A Array which holds all the files names found in a specfic folder it only moves forward as well I assume you will be able to figure out how to make a previous link this code is also set to page by the size of 10 you can increase this at your will. I hope this gets you off your stump.
findel | Posted 5:30am 19. July 2002 Server Time |
Qoute:
---------------------------------
I hope this gets you off your stump.
---------------------------------
Why do i have a mental picture of alangford sitting on a cut down tree with a laptop?
alangford | Posted 6:33am 19. July 2002 Server Time |
Thanks for your help Informant!
It works nicely. Now I'm new to asp so you're going to have to help me out a little.
Why does the first page start out at 0? Why does the next page always start out with the last page number from the previous one?
http://www.athleticconnection.com/pdfCatalog.asp
I think I know how to do the prev button working backwords from the next but I'm not sure what you mean by "does not have a Stop Size set".
You help and time is much appreciated!
Ashley
alangford | Posted 7:44am 19. July 2002 Server Time |
Here's my code.
<table width="760" border="0" cellspacing="3" cellpadding="3">
<tr>
<td class="mytext">Page
<%
'Create the FileSystemObject object
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Obtain an folder object instance for a particular directory
Dim objFolder
Set objFolder = objFSO.GetFolder("D:Inetpub\AthleticConnection\wwwroot\PDFs\")
'Use a For Each ... Next loop to display the files
Dim objFile
Dim currentPage
Dim ArrayOfPDFs()
For Each objFile In objFolder.Files
currentPage = currentPage + 1
Redim Preserve ArrayOfPDFS(currentPage)
ArrayOfPDFS(currentPage) = objFile.Name
Next
Dim Start
Dim StopPoint
Dim MaxSize
MaxSize = Ubound(ArrayOfPDFS)
If Request.QueryString("Start") = "" and Request.QueryString("StopPoint") = "" Then
Start = 0
StopPoint = 10
Else
Start = Request.QueryString("Start") + 10
StopPoint = Request.QueryString("StopPoint") + 10
prevStart = Request.QueryString("Start") - 10
prevStopPoint = Request.QueryString("StopPoint") - 10
End if
For i = Start to StopPoint
Response.Write "<a href='PDFs/"& ArrayOfPDFS(i) &"'>" & i & "</a> "
Next
%>
</td>
<td class="mytext" align="right">
<%
Response.Write "<a href=pdfCatalog.asp?StopPoint=" & prevStopPoint & "&Start=" & prevStart & ">Prev</a> "
Response.Write "<a href=pdfCatalog.asp?StopPoint=" & StopPoint & "&Start=" & Start & ">Next</a>"
%>
</td>
</tr>
<tr>
<td class="mytext"> </td>
<td class="mytext" align="right">Output Variables:
PrevStart
<%Response.Write (prevStart)%>
PrevStopPoint
<%Response.Write (prevStopPoint)%>
</td>
</tr>
</table>
Here's the link to execute this code.
http://www.athleticconnection.com/pdfCatalog.asp
Thanks!
Informant | Posted 8:40am 19. July 2002 Server Time |
What I mean by not having a stop point was if you keep paging through and you exceed the amount of files in a specified folder it will error meaning no stop point has been set.
alangford | Posted 8:55am 19. July 2002 Server Time |
That makes sense.
What about ...
Why does the first page start out at 0? Why does the next page always start out with the last page number from the previous one?
Thanks!
Informant | Posted 10:09am 19. July 2002 Server Time |
Here is what I did...
I created a Dynamic Array that would store all the names of each file found in a specified directory I did this because you can reuse a array a lot more rescourcefully rather then having to use the collection of the FSO to grab items from a folder. You can reuse and parse through a array and even grab specfic values, but anyway the Array's always start at the index of 0 so the first filename that was found was stored in the first index of the array(0). So I start and the index of 0 and create a paging stop point of 10 and what this does is give me 10 files names in return and everytime I hit next it takes the current value of each array's current value and adds 10 to both therefore giving you the next ten items and so on and so forth. Does that make sense?
alangford | Posted 12:42am 19. July 2002 Server Time |
Yes, that does make sense. You'll have to excuse me but arrays give me trouble. I come from a design background but my brain has adopted *some* programming skills. You were very helpful.
Ashley
Romans 10:9
Reply to Post Paging through FileSystemObject
|
|
|