|
-
Sep 1st, 2012, 11:32 AM
#1
Thread Starter
Hyperactive Member
Managing a IE Download in the background
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:
Private Sub btnDownload_Click(sender As System.Object, e As System.EventArgs) Handles btnDownload.Click Dim Tday, TMonth, TYear, TDate As String Tday = Date.Now.Day TMonth = Date.Now.Month TYear = Date.Now.Year Tday.Replace("0", "") TMonth.Replace("0", "") TDate = (Tday & "." & TMonth & "." & TYear) Webaddress = (Website Address) WebBrowser1.Navigate(Webaddress) Timer1.Start() End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete Application.DoEvents() Loop If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then btnlogin.PerformClick() Timer1.Stop() End If End Sub Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click WebBrowser1.Document.All("ssousername").InnerText = "Username" WebBrowser1.Document.All("password").InnerText = "Password" Dim theElementCollection As HtmlElementCollection theElementCollection = WebBrowser1.Document.GetElementsByTagName("input") For Each curElement As HtmlElement In theElementCollection If curElement.GetAttribute("value").Equals("Login") Then curElement.InvokeMember("click") End If Next End Sub
If anyone could shed some light on this.
Mega Thanks in Advance
Alex
-
Sep 1st, 2012, 11:44 AM
#2
Re: Managing a IE Download in the background
-
Sep 1st, 2012, 03:05 PM
#3
Thread Starter
Hyperactive Member
Re: Managing a IE Download in the background
 Originally Posted by dunfiddlin
Ok so I used the code on there, but it has downloaded the sign in page. any help on this?
-
Sep 1st, 2012, 03:47 PM
#4
Re: Managing a IE Download in the background
You still need to log in. Very often the log in page and the home page have the same address. You also need the complete filename for the download.
-
Sep 2nd, 2012, 07:38 AM
#5
Thread Starter
Hyperactive Member
Re: Managing a IE Download in the background
 Originally Posted by dunfiddlin
You still need to log in. Very often the log in page and the home page have the same address. You also need the complete filename for the download.
how do I go about logging in.
the current code downloads the sign in page and inserts the filename into the username box. The url I link to is the file but you have to sign in first. as soon as you hit the login button it generates and downloads the report.
vb.net Code:
Dim Tday, TMonth, TYear, TDate As String Tday = Date.Now.Day TMonth = Date.Now.Month TYear = Date.Now.Year Tday.Replace("0", "") TMonth.Replace("0", "") TDate = (Tday & "." & TMonth & "." & TYear) Webaddress1 = ("THE URL") Dim remoteUri As String = Webaddress1 Dim fileName As String = "00-3052.xls" Dim myStringWebResource As String = Nothing Dim myWebClient As New WebClient() myStringWebResource = remoteUri + fileName myWebClient.DownloadFile(myStringWebResource, fileName)
The url (ive replaced sensitive info)
"http://XXXX.com:PORT/reports/00-3052.jsp?SOME_OTHER_INFO_HERE&P_FROM_DATE=" & TDate & "&P_TO_DATE=" & TDate)
The Sign in page consists of
Username textbox. Html name = ssousername
Password textbox. html name = password
submit button. html name = login
it will ask for the username and password every time, even if you have signed in once and then go to it.
Last edited by crampz; Sep 2nd, 2012 at 07:53 AM.
-
Sep 2nd, 2012, 09:54 AM
#6
Re: Managing a IE Download in the background
Ah, right. That could be a problem. I'm sure you used to be able to override the dialog in Internet Options but if that ever was the case it certainly isn't now. There's probably a registry entry that will do it but the truble with that, of course, is that you'd override the dialog for everything, which may not be desirable. The only thing left would be to capture the dialog and press 'save' automatically. I'll have a little play and see if that's possible.
In the meantime do I take the removal of 'sensitive' information as an indication that you have a direct relationship with the server? In that case you might ask whether there is an API or at least an alternative log in method that would obviate the problem directly.
Last edited by dunfiddlin; Sep 2nd, 2012 at 10:07 AM.
-
Sep 2nd, 2012, 10:39 AM
#7
Thread Starter
Hyperactive Member
Re: Managing a IE Download in the background
 Originally Posted by dunfiddlin
Ah, right. That could be a problem. I'm sure you used to be able to override the dialog in Internet Options but if that ever was the case it certainly isn't now. There's probably a registry entry that will do it but the truble with that, of course, is that you'd override the dialog for everything, which may not be desirable. The only thing left would be to capture the dialog and press 'save' automatically. I'll have a little play and see if that's possible.
In the meantime do I take the removal of 'sensitive' information as an indication that you have a direct relationship with the server? In that case you might ask whether there is an API or at least an alternative log in method that would obviate the problem directly.
ahh ok I see. Just replying on mobile atm. Thank you for your help in advance. I just removed information as it just contained company name and some parameters that had info on it. I don't have direct access to it. Just access through our companies reporting tools.
-
Sep 2nd, 2012, 01:48 PM
#8
Thread Starter
Hyperactive Member
Re: Managing a IE Download in the background
Ok Question, Can I pass request headers to the webbrowser. I captured data of me downloading the file. so I have the capture information of the login and then of the download. I don't know if I can do anything with this
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|