|
-
Dec 19th, 2003, 05:46 AM
#1
Thread Starter
Hyperactive Member
*RESOLVED* downloading files
Hi everybody,
I have a webserver that holds a number of pdf-files.
I want to be able to download these files.
So I want to be able to show all the files in a specific directory, and sort them by date.
I think I have to use the FSO, but I'm not very familiar with it 
Any help is very much appreciated
Last edited by mvrp350; Jan 15th, 2004 at 08:16 AM.
-
Dec 19th, 2003, 10:25 AM
#2
-
Dec 19th, 2003, 10:35 AM
#3
Thread Starter
Hyperactive Member
Thanks Danial,
It is only 1 folder, with no subfolders.
I have the code for listing the files, but not sorted 
VB Code:
Dim objFileScripting, objFolder
dim filename, filecollection, strDirectoryPath, strUrlPath
strDirectoryPath="c\myfolder\"
strUrlPath="\myfolder\"
'get file scripting object
Set objFileScripting = CreateObject("Scripting.FileSystemObject")
'Return folder object
Set objFolder = objFileScripting.GetFolder("c:\myfolder\")
'return file collection in folder
Set filecollection = objFolder.Files
'create the links
For Each filename in filecollection
Filename=right(Filename,len(Filename)-InStrRev(Filename, "\"))
if ucase(right(filename,9)) = "*.PDF" then
Response.Write "<A HREF=""" & strUrlPath & filename & """>" & filename & "</A><BR>"
response.write vbcrlf
response.write "<BR>"
response.write vbcrlf
end if
Next
-
Dec 19th, 2003, 10:48 AM
#4
Here is example of sorting using ADO recordset i found on the net. Try it out, see if it works, if not then let me know.
VB Code:
<%' Now to the Runtime code:
Dim strPath 'Path of directory to show
Dim objFSO 'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem 'Variable used to loop through the contents of the folder
' A recordset object variable and some selected constants from adovbs.inc.
' I use these for the sorting code.
Dim rstFiles
Const adVarChar = 200
Const adInteger = 3
Const adDate = 7
' You could just as easily read this from some sort of input, but I don't
' need you guys and gals roaming around our server so I've hard coded it to
' a directory I set up to illustrate the sample.
' NOTE: As currently implemented, this needs to end with the /
strPath = "C:\WINDOWS\Profiles\hongjun\Desktop\CheckAscii"
' Create our FSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Get a handle on our folder
Set objFolder = objFSO.GetFolder(strPath)
Set rstFiles = Server.CreateObject("ADODB.Recordset")
rstFiles.Fields.Append "name", adVarChar, 255
rstFiles.Open
For Each objItem In objFolder.Files
rstFiles.AddNew
rstFiles.Fields("name").Value = objItem.Name
Next 'objItem
' All done! Kill off our File System Object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
' Now we can sort our data and display it:
' Sort ascending by size and secondarily descending by date
' (by date is mainly for illustration since all our files
' are different sizes)
rstFiles.Sort = "name asc"
rstFiles.MoveFirst
Do While Not rstFiles.EOF
Response.Write rstFiles.Fields("name").Value & "<br>"
rstFiles.MoveNext
Loop
' Close our ADO Recordset object
rstFiles.Close
Set rstFiles = Nothing
%>
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Dec 21st, 2003, 09:57 PM
#5
Junior Member
Code for downloading
This is what i have for vb6.0 to download files, but be warry..
Somtimes i used it in some of my programs, users say it opens dangerous ports, u might want to check it out (use active ports)
for me it never does such things...
VB Code:
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 1
VB Code:
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Call the fucntion this way..
VB Code:
DownloadFile "http://www.mahjoob.com/index.jpg", "Location to save in"
Hope i understood u right
Peace,
-
Dec 21st, 2003, 10:30 PM
#6
I think he is looking for a way to Sort the List of files rather then be able to download them.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jan 15th, 2004, 08:15 AM
#7
Thread Starter
Hyperactive Member
Thanks guys,
Danial, the problem has been resolved. A small change to the code did the trick:
VB Code:
'create the recordset
Set rstFiles = Server.CreateObject("ADODB.Recordset")
rstFiles.Fields.Append "name", adVarChar, 255
rstFiles.Fields.Append "date", adDate
rstFiles.Open
'loop and fill the recordset
For Each file In objFolder.Files
rstFiles.AddNew
rstFiles.Fields("name").Value = file.Name
rstFiles.Fields("date").Value = file.DateCreated
Next
rstFiles.Sort = "date desc"
Last edited by mvrp350; Jan 15th, 2004 at 08:19 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|