Login   /   Register

Saving a file from Internet Explorer

Rate this article
     3 votes, average: 4.67 out of 53 votes, average: 4.67 out of 53 votes, average: 4.67 out of 53 votes, average: 4.67 out of 53 votes, average: 4.67 out of 5
Loading ... Loading ...
July 12th, 2008 by Yaron Assa

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

Posted in Web

3 Responses to “Saving a file from Internet Explorer”

  1. sr.manem Says:

    [+]

    This program is good. It will be more good if you give comments to the programming lines. So that it will be easy to understand fo... ...

  2. miken Says:

    [+]

    Interesting exercise in codeing but would be better if you could describe a situation where i would want to write all that code in... ...

  3. michael.tewierik@jds.net.au Says:

    [+]

    While I appreciate sr.manem's point about commenting, to add more commenting to such a straight forward code would defeat the purp... ...

Leave a Reply

You must be logged in to post a comment.

This article was viewed 979 times