Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42441

VS 2010 Managing a IE Download in the background

$
0
0
Hi All

(me again!) lol

Anyway, this is where I have got to, and now I'm stuck.

I use a webbrowser to navigate to a site and log in. The site that I navigate to is actually the link to the download but you have got to login first and once you click submit on the login form it then starts the download.

So where I get to is logging in, but I get the IE File download dialog "Open, Save or Cancel".

What I want to do is to be able to download and save this file in the directory of the application all in the background, without the user having to interact with anything.

The file is always a excel file (.xls)

vb.net Code:
  1. Private Sub btnDownload_Click(sender As System.Object, e As System.EventArgs) Handles btnDownload.Click
  2.         Dim Tday, TMonth, TYear, TDate As String
  3.         Tday = Date.Now.Day
  4.         TMonth = Date.Now.Month
  5.         TYear = Date.Now.Year
  6.         Tday.Replace("0", "")
  7.         TMonth.Replace("0", "")
  8.         TDate = (Tday & "." & TMonth & "." & TYear)
  9.         Webaddress = (Website Address)
  10.         WebBrowser1.Navigate(Webaddress)
  11.         Timer1.Start()
  12.     End Sub
  13.  
  14.     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
  15.         Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
  16.             Application.DoEvents()
  17.         Loop
  18.         If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
  19.             btnlogin.PerformClick()
  20.             Timer1.Stop()
  21.         End If
  22.     End Sub
  23.  
  24.     Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
  25.         WebBrowser1.Document.All("ssousername").InnerText = "Username"
  26.         WebBrowser1.Document.All("password").InnerText = "Password"
  27.         Dim theElementCollection As HtmlElementCollection
  28.         theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
  29.         For Each curElement As HtmlElement In theElementCollection
  30.             If curElement.GetAttribute("value").Equals("Login") Then
  31.                 curElement.InvokeMember("click")
  32.             End If
  33.         Next
  34. End Sub

If anyone could shed some light on this.

Mega Thanks in Advance

Alex

Viewing all articles
Browse latest Browse all 42441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>