Results 1 to 3 of 3

Thread: download a file from website not working

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Location
    Texas
    Posts
    144

    download a file from website not working

    Hi,
    I used the below code in my project but the result was not what I expected. Can anyone help explain why the file downloaded is the same file every time despite I uploaded an updated version file with the same file name to the website?

    Here is the scenario, I put a text file named "test.txt" with the content of "1234" on an Internet website. When the code below is executed the very first time, the file was downloaded, and everything is working as expected. However, if I put an updated text file with the same name but changed the content to "abcd" on the website. Now when I execute the code again to download test.txt, the file downloaded successfully but the content is still the same, "1234", despite I deleted the file in c:\test.txt. So far I can fix this problem only if I went into the browser setting and cleared the history, deleted the cookies, and delete Internet temporary files, then the download will get the updated file posted on the web with the new content of "abcd". It seemed as if it cached the file name in IE for some reasons.

    Any helps would be greatly appreciated.

    VB Code:
    1. 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
    2.  
    3. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    4.     Dim lngRetVal As Long
    5.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    6.     If lngRetVal = 0 Then DownloadFile = True
    7. End Function
    8.  
    9. Sub main()
    10.     DownloadFile "http://mywebsite.home.comcast.net/test.txt", "c:\test.txt"
    11. end sub

  2. #2
    New Member
    Join Date
    Dec 2006
    Posts
    5

    Re: download a file from website not working

    try this

    Code:
    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
    
    ****************************************************
    
    Sub main()
    
    Dim DFile, FullLink As String
    DFile = "C:\test.txt"
    FullLink = "http://mywebsite.home.comcast.net/test.txt"
    DownloadData
    
    End Sub
    
    ****************************************************
    
    Sub DownloadData()
         
    If URLDownloadToFile(0, FullLink, DFold & DFile, 0, 0) = 0 Then
        Workbooks.Open Filename:=DFile
    End If
    
    End Sub
    ska
    Last edited by ska67can; Jan 19th, 2007 at 08:03 AM.

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: download a file from website not working

    Hi

    I found this on msdn...

    http://www.microsoft.com/mspress/boo.../6436.aspx#132

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

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