Results 1 to 7 of 7

Thread: *RESOLVED* downloading files

  1. #1

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322

    *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.

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: downloading files

    Originally posted by mvrp350
    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
    I can give you the code which displays all the files in a specific folder using FSO, it does not sort the files though. Is it only a single folder or does it contain subfolders too?

    What you can do is put the file name into an array and then sort it. I will see if i can put it together for you.

    Danial
    [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 :

  3. #3

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    Thanks Danial,

    It is only 1 folder, with no subfolders.
    I have the code for listing the files, but not sorted

    VB Code:
    1. Dim objFileScripting, objFolder
    2.     dim filename, filecollection, strDirectoryPath, strUrlPath
    3.         strDirectoryPath="c\myfolder\"
    4.         strUrlPath="\myfolder\"
    5.        
    6.         'get file scripting object
    7.         Set objFileScripting = CreateObject("Scripting.FileSystemObject")
    8.         'Return folder object
    9.         Set objFolder = objFileScripting.GetFolder("c:\myfolder\")
    10.         'return file collection in folder
    11.         Set filecollection = objFolder.Files
    12.         'create the links
    13.         For Each filename in filecollection
    14.             Filename=right(Filename,len(Filename)-InStrRev(Filename, "\"))
    15.             if ucase(right(filename,9)) = "*.PDF" then
    16.                 Response.Write "<A HREF=""" & strUrlPath & filename & """>" & filename & "</A><BR>"
    17.             response.write vbcrlf
    18. response.write "<BR>"
    19. response.write vbcrlf
    20.             end if
    21.         Next

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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:
    1. <%' Now to the Runtime code:
    2. Dim strPath   'Path of directory to show
    3. Dim objFSO    'FileSystemObject variable
    4. Dim objFolder 'Folder variable
    5. Dim objItem   'Variable used to loop through the contents of the folder
    6.  
    7. ' A recordset object variable and some selected constants from adovbs.inc.
    8. ' I use these for the sorting code.
    9. Dim rstFiles
    10. Const adVarChar = 200
    11. Const adInteger = 3
    12. Const adDate = 7
    13.  
    14.  
    15. ' You could just as easily read this from some sort of input, but I don't
    16. ' need you guys and gals roaming around our server so I've hard coded it to
    17. ' a directory I set up to illustrate the sample.
    18. ' NOTE: As currently implemented, this needs to end with the /
    19. strPath = "C:\WINDOWS\Profiles\hongjun\Desktop\CheckAscii"
    20.  
    21. ' Create our FSO
    22. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    23.  
    24. ' Get a handle on our folder
    25. Set objFolder = objFSO.GetFolder(strPath)
    26.  
    27. Set rstFiles = Server.CreateObject("ADODB.Recordset")
    28. rstFiles.Fields.Append "name", adVarChar, 255
    29. rstFiles.Open
    30.  
    31. For Each objItem In objFolder.Files
    32.     rstFiles.AddNew
    33.     rstFiles.Fields("name").Value = objItem.Name
    34. Next 'objItem
    35.  
    36. ' All done!  Kill off our File System Object variables.
    37. Set objItem = Nothing
    38. Set objFolder = Nothing
    39. Set objFSO = Nothing
    40.  
    41. ' Now we can sort our data and display it:
    42.  
    43. ' Sort ascending by size and secondarily descending by date
    44. ' (by date is mainly for illustration since all our files
    45. '  are different sizes)
    46. rstFiles.Sort = "name asc"
    47.  
    48. rstFiles.MoveFirst
    49.  
    50. Do While Not rstFiles.EOF
    51.     Response.Write rstFiles.Fields("name").Value & "<br>"
    52.     rstFiles.MoveNext
    53. Loop
    54.  
    55. ' Close our ADO Recordset object
    56. rstFiles.Close
    57. Set rstFiles = Nothing
    58.  
    59. %>
    [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 :

  5. #5
    Junior Member
    Join Date
    May 2003
    Location
    NYC
    Posts
    16

    Arrow 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:
    1. Option Explicit
    2. 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
    3. Private Declare Function ShellExecute Lib _
    4.               "shell32.dll" Alias "ShellExecuteA" _
    5.               (ByVal hwnd As Long, _
    6.                ByVal lpOperation As String, _
    7.                ByVal lpFile As String, _
    8.                ByVal lpParameters As String, _
    9.                ByVal lpDirectory As String, _
    10.                ByVal nShowCmd As Long) As Long
    11.                
    12. Private Const SW_SHOW = 1


    VB Code:
    1. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    2.     Dim lngRetVal As Long
    3.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    4.     If lngRetVal = 0 Then DownloadFile = True
    5. End Function

    Call the fucntion this way..

    VB Code:
    1. DownloadFile "http://www.mahjoob.com/index.jpg", "Location to save in"

    Hope i understood u right

    Peace,

  6. #6
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  7. #7

    Thread Starter
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    Thanks guys,

    Danial, the problem has been resolved. A small change to the code did the trick:

    VB Code:
    1. 'create the recordset
    2. Set rstFiles = Server.CreateObject("ADODB.Recordset")
    3. rstFiles.Fields.Append "name", adVarChar, 255
    4. rstFiles.Fields.Append "date", adDate
    5. rstFiles.Open
    6.  
    7. 'loop and fill the recordset
    8. For Each file In objFolder.Files
    9.        rstFiles.AddNew
    10.        rstFiles.Fields("name").Value = file.Name
    11.        rstFiles.Fields("date").Value = file.DateCreated
    12. Next
    13.  
    14. 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
  •  



Click Here to Expand Forum to Full Width