vbscript - Download File from reporting services using VBA -


i have script file. attempting download reporting services using xmlhttp. if paste url in browser after logging in, file pops download. when running code below, not work (the code work downloading direct file links"

how can post parameters , download file report server? appreciate on 1 guys. here code working with:

myurl = "http://example.com/reportviewer.aspx?id=1&date=1/3/12&format=pdf"  dim winhttpreq object set winhttpreq = createobject("microsoft.xmlhttp") winhttpreq.open "get", myurl, false, "user", "pwd" winhttpreq.send  myurl = winhttpreq.responsebody if winhttpreq.status = 200     set ostream = createobject("adodb.stream")     ostream.open     ostream.type = 1     ostream.write winhttpreq.responsebody     ostream.savetofile "c:\file.pdf", 2      ostream.close  end if 

by way file returned (file.pdf) if rename file.html , double click it. internet explorer automatically popups download notification. tried view source of file, link unique report execution id, 1 report. also, link in there not pdf file report server.

the url has 100% correct. unlike browser there no code fix urls.

the purpose of program error details.

try way using xmlhttp. edit url's etc. if seems work comment out if / end if dump info if seeming work. it's vbscript vbscript works in vb6.

 on error resume next  set file = wscript.createobject("microsoft.xmlhttp")  file.open "get", "http://www.microsoft.com/en-au/default.aspx", false  'this ie 8 headers  file.setrequestheader "user-agent", "mozilla/4.0 (compatible; msie 8.0; windows nt 6.0; trident/4.0; slcc1; .net clr 2.0.50727; media center pc 5.0; .net clr 1.1.4322; .net clr 3.5.30729; .net clr 3.0.30618; .net4.0c; .net4.0e; bcd2000; bcd2000)"  file.send  if err.number <> 0      line =""     line  = line &  vbcrlf & ""      line  = line &  vbcrlf & "error getting file"      line  = line &  vbcrlf & "=================="      line  = line &  vbcrlf & ""      line  = line &  vbcrlf & "error " & err.number & "(0x" & hex(err.number) & ") " & err.description      line  = line &  vbcrlf & "source " & err.source      line  = line &  vbcrlf & ""      line  = line &  vbcrlf & "http error " & file.status & " " & file.statustext     line  = line &  vbcrlf &  file.getallresponseheaders     wscript.echo line     err.clear     wscript.quit  end if  on error goto 0   set bs = createobject("adodb.stream")  bs.type = 1  bs.open  bs.write file.responsebody  bs.savetofile "c:\users\test.txt", 2 

also see if these other objects work.

c:\users>reg query hkcr /f xmlhttp  hkey_classes_root\microsoft.xmlhttp hkey_classes_root\microsoft.xmlhttp.1.0 hkey_classes_root\msxml2.serverxmlhttp hkey_classes_root\msxml2.serverxmlhttp.3.0 hkey_classes_root\msxml2.serverxmlhttp.4.0 hkey_classes_root\msxml2.serverxmlhttp.5.0 hkey_classes_root\msxml2.serverxmlhttp.6.0 hkey_classes_root\msxml2.xmlhttp hkey_classes_root\msxml2.xmlhttp.3.0 hkey_classes_root\msxml2.xmlhttp.4.0 hkey_classes_root\msxml2.xmlhttp.5.0 hkey_classes_root\msxml2.xmlhttp.6.0 end of search: 12 match(es) found. 

also aware there limit on how many times can call particular xmlhttp object before lockout occurs. if happens, , when debugging code, change different xmlhttp object


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -