none
The Compressed Folder is Invalid.

    Question

  • I have a url i can go to and manually download a zip file and it comes into my Download folder fine; I can open and see everything (a bunch of csv files).

    But when I write script in vba to download the same zip file to a MyDocuments folder I get the error "Windows cannot open Folder. The compressed file xxxx is invalid.

    Any idea what I'm doing wrong?

    thanks

    Friday, August 31, 2012 4:17 PM

All replies

  • Hi,

    Based on my research, all downloaded data is treated as string and not binary. For this reason the binary ZIP files are corrupted most likely related to the following statements:

    Dim strBuffer As String * BUFFER_SIZE
    and
    strBuffer = Left(strBuffer, lngRead)

    The problem can most likely be solved by replacing the string with a byte array. This is to ensure that there is no string conversion.


    Jaynet Zhang

    TechNet Community Support

    Monday, September 03, 2012 7:28 AM
  • Hi Jaynet,

    I tried to dimension a .responsebody variable as a string and it wouldn't work. (Still downloads the zip file but shows up as invalid. 

    And then tried dimensioning a fleBte array as Byte and writing that instead. 

    Still won't work. Same result. Am I doing something wrong? Thanks

    Sub DownloadFile4(url As String, LocalFile As String)

    Dim fle As Variant
    Dim fleBte() As Byte

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", url
        .Send
        Do: DoEvents: Loop Until .readystate = 4
        fle = .responsebody
        fleBte = StrConv(fle, vbFromUnicode)
        With CreateObject("ADODB.Stream")
            .Open
            .Type = 1
            .Write fle
            .Position = 0
            .SaveToFile LocalFile
            .Close
        End With
        .Abort
    End With

    End Sub

    Tuesday, September 04, 2012 12:56 PM
  • Jaynet, when i do debug.print on what is returned to fle I get this.

    thanks for looking

    ????????????????????????????????????????????????????????????????????????????????????????????•???????????????????????????????•????????=????????????????????????????????????????•??????????????????????????????????????????????????????•??????????????????????????????????????????????????????????????????????????????•?????????????????????????????????????????????????4??????•???????•????????????????????????????????????††††?†††?††††?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
    ???????????6??????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6??????????????????????????????????????????????????????????????????????????6?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????n???4?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6??????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6???
    ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6??????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6??????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6???????????????????????????????
    ???????

    Tuesday, September 04, 2012 1:35 PM