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


Yaron Assa




July 21st, 2008 at 3:14 pm
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 for the beginners.
Thanx for this useful article
July 29th, 2008 at 5:24 pm
Interesting exercise in codeing but would be better if you could describe a situation where i would want to write all that code in place of simply recording a right-click and selecting ’save as’ like i have always done.
August 1st, 2008 at 4:03 am
While I appreciate sr.manem’s point about commenting, to add more commenting to such a straight forward code would defeat the purpose of posting on “AdvancedQTP”.
At a glance I can see what each section does and the appropriate commenting has been given indicating the following steps sets.
I would recommend sr.manem takes the code, adding in the extra comments that he/she thinks are appropriate and adding it to the “First steps” section with appropriate credit reference to Anshoo.
Good work Anshoo, very clear and I cant wait to give it a try when the need arises.