Saving a File from Internet Explorer

Article Tools

Anshoo Arora has a great QTip for saving a file via Internet Explorer. This will produce similar results to manually right-clicking a link and choosing “Save as”:

'Simulate a web query
Set WinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
If WinHttp Is Nothing Then Set WinHttp = CreateObject("WinHttp.WinHttpRequest")
WinHttp.Open "GET", "http://www.website.com/Documnet_i_want_to_save.pdf", False
WinHttp.Send

'Get the response
arrArray = WinHttp.ResponseBody
Set WinHttp = Nothing

'Write the response
On Error Resume Next
    Set oADO = CreateObject("ADODB.Stream")
    If oADO Is Nothing Then
        'Write via FSO
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        Set oTextFile = oFSO.OpenTextFile("c:\Documnet_i_want_to_save.pdf", 2, True)
        sData = ""
        sBuffer = ""
        For iCount = 0 to UBound(arrArray)
            oTextFile.Write Chr(255 And Ascb(Midb(arrArray,iCount + 1, 1)))
        Next
        oTextFile.Close
    Else
        'Write via ADO
        oADO.Type = 1
        oADO.Open
        oADO.Write arrArray
        oADO.SaveToFile "c:\Documnet_i_want_to_save.pdf", 2
        oADO.Close
    End If

    Set oADO = Nothing
    Set oTextFile = Nothing
    Set oFSO = Nothing

 

Thanks Anshoo for this great QTips

Previous postQTP Intellisense Resizer Next postDisabling a Network Adapter

Related Posts

Post Your Comment

You must be logged in to post a comment.