473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

download web document VB.NET

seraieis
Good morning experts!

I'm trying to figure out a way to download a report from one of my companies intranet sites, and I've hit a bit of a snag.

The report differs by two items: the session id (auto-generated on log on), and the report key (which I get from another system). I've used screen scraping to get the session ID at log on, and I provide the key.

However, when I try to use My.Computer.Network.DownloadFile, the file that downloads is a page (within the system) that says the session has expired. I have a feeling it's because there's a web-based application that generates the report.
Expand|Select|Wrap|Line Numbers
  1.         path = _
  2.             "http://system.internal.com/xcgi/xnet.exe?sys=sys" & _
  3.             "&ses=" & session & _
  4.             "&ISN=&TRN=&cmd=DWN&rid=" & _
  5.             "&rpt=/EDICLAIM/HOSPMED%2ECCMEDC%2E%4002" & _
  6.             "&ver=1722" & _
  7.             "&ixn=" & s & "&ixv=" & key
  8.  
  9.         Try
  10.             Dim file As String = _
  11.                 My.Computer.FileSystem.SpecialDirectories.Desktop _
  12.                 & "\test.xls"
  13.             If My.Computer.FileSystem.FileExists(file) Then Kill(file)
  14.             My.Computer.Network.DownloadFile(path, file)
  15.             Process.Start(file)
  16.         Catch ex As Exception
  17.             MsgBox(ex.Message)
  18.         End Try
  19.  
Now, if I copy the string into the browser, it opens a file download dialog and I can save it as normal. However, trying to use VB to do the same results in an error. Does anyone have any suggestions as to how to overcome this?

Thank you!
Jul 30 '08 #1
5 1636
Plater
7,872 Expert 4TB
You should be using HttpWebRequest to download the file should you not?
Jul 30 '08 #2
It's funny you should say that! I continued trying to figure this out, and just tested using that:
Expand|Select|Wrap|Line Numbers
  1.             Dim request As HttpWebRequest = WebRequest.Create(path)
  2.             Dim response As HttpWebResponse = request.GetResponse()
  3.             Dim reader As New StreamReader(response.GetResponseStream())
  4.             Dim f As New IO.StreamWriter(file)
  5.  
  6.             f.Write(reader.ReadToEnd())
  7.             f.Close()
  8.             reader.Close()
  9.  
  10.             Process.Start(file)
  11.  
The file that opens after this runs is still the error page. Is there something I'm missing?
Jul 30 '08 #3
Plater
7,872 Expert 4TB
You may need to do the entire process for grabbing the session id and etc with HttpWebRequest objects?

If you paste the path you provided into a new IE (or FF) window, does it give the correct response? (I say new window, but I mean new instance, re-using an old instance might send down hidden headers obtained from a previous successfull request to the website)
Jul 30 '08 #4
I tried copying the address into another window and it gave the error page.

Looking at the JavaScript behind the web page's download button, it looks simple enough:
Expand|Select|Wrap|Line Numbers
  1. function goToDownload() {
  2.   if (GetCookie("actind") == "") {
  3.      window.location = "/xcgi/xnet.exe?sys=JHSE2&ses=0ECCE09B851B522572AFFB6451E39C6F55EAFFDC&ISN=&TRN=&cmd=DWN&rid=&rpt=/CLM/HOSPMED%2ECCMEDC%2E%4002&ver=1722&ixn=CKEY$&ixv=2008011840100401017442";
  4.   }
  5. }
  6.  
The string generate by the program:
Expand|Select|Wrap|Line Numbers
  1. xcgi/xnet.exe?sys=JHSE2&ses=0ecce09b851b522572affb6451e39c6f55eaffdc&ISN=&TRN=&cmd=DWN&rid=&rpt=/CLM/HOSPMED%2ECCMEDC%2E%4002&ver=1722&ixn=CKEY$&ixv=2008011840100401017442
  2.  
Now, I know nothing about cookies, so I'm not sure that it's referencing. Plus, reading through the cookie itself, I couldn't find anything with a label of "actind", so I'm a little confused.

Is there a way to trick the WebRequest into thinking it's coming from the same instance?
Jul 30 '08 #5
I had a breakthrough!

Expand|Select|Wrap|Line Numbers
  1.         Dim d As System.Windows.Forms.HtmlDocument = Me.WebBrowser1.Document
  2.         d.InvokeScript("goToDownload")
  3.  
That brings up the dialog box for saving something from the internet to your computer. Now, short of simulating keystrokes, is there a way to NOT have the save file dialog box appear?
Jul 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James Kirk | last post by:
The script below allows me to link to a file and as the user clicks to download, the 'File Download' windows appears as normal, and the user can download... The original page is then redirected...
8
by: lawrence | last post by:
Under the domain publicpen.com I've several dozen sites in subdiretories, such as www.publicpen.com/honenbeger. I've no trouble with any of these sites. But under one, which I put in yesterday,...
4
by: D. Alvarado | last post by:
Hello, I would like to design a page that measures the user's download connection. Does anyone have an example link or script that might aid me in this task? Thanks, - Dave
4
by: gb | last post by:
hi, i placed System.Windows.Forms.WebBrowser in my WinForm. When i tried loading word document, it opens the File Download window. My question is how can i avoid the File Download window from...
4
by: zbcong | last post by:
hello i find following link: http://www.microsoft.com/seminar/events/webcasts/library/default.mspx that could link to archieved online webcast,but i can't find how to download them.who can tell...
7
by: Brian Paul | last post by:
When a user clicks on a linkbutton on a page, i would like to render a printer-friendly version of the asp.net page and download it as an html attachment to the browser. The code below works great,...
3
by: ACaunter | last post by:
Hi there, when one of my pages loads up, the download dialog box pops up to download a file.. but the window turns all white and even after you download the file, the window stays white.. what...
1
by: harold.saldanha | last post by:
My objective is to redirect to another web page after download is complete. I have an activeX called to download a few dlls using the following code document.writeln(' <OBJECT ID="MQC" ');...
2
by: torbjorn.maro | last post by:
I'm the developer of an enterprise level web application that among other things handles documents. The documents are stored in a database. There is now simple functionality to check out and...
1
Ciary
by: Ciary | last post by:
hey all, i have another problem. basically the question is: how do i make sure a file is downloaded instead of opened? but i'll explain the situation. i'm trying to download a file using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.