1

I am trying to download tracking information from FedEx's website. First I have to pass login credentials and then navigate to a webpage which triggers an automatic download. My code so far works fine for this. However; as soon as the download is triggered a popup comes up asking if I want to save the file and then when I click save I asks where I want to save the file to. I want to disable the popups and have the file just automatically saved in my downloads folder. Is there a way to do this? Thanks in advance for any help! Here is my code so far.

    Dim WebBrowser1 As New WebBrowser
    Dim url As String = "https://www.fedex.com/insight/manifest/manifest.jsp?&__QS=252D0F3B4E380B211B122B1A09251510050E0F5C273A223E34360539237976645E45745E57776C&"
    WebBrowser1.Navigate(url)
    WebBrowser1.ScriptErrorsSuppressed = True
    Threading.Thread.Sleep(2000)
    Application.DoEvents()
    Do Until WebBrowser1.IsBusy = False
        Threading.Thread.Sleep(1000)
        Application.DoEvents()
    Loop
    WebBrowser1.Document.GetElementById("username").SetAttribute("value", "MyUsername")
    WebBrowser1.Document.GetElementById("password").SetAttribute("value", "MyP@ssw0rd")
    WebBrowser1.Document.GetElementById("login").InvokeMember("click")
    Threading.Thread.Sleep(1000)
    Application.DoEvents()
    Do Until WebBrowser1.IsBusy = False
        Threading.Thread.Sleep(1000)
        Application.DoEvents()
    Loop
    WebBrowser1.Navigate("https://www.fedex.com/insight/manifest/download_post.jsp?VIEW=|Outbound_View&INFOTYPE=STATUS")
    Do Until WebBrowser1.IsBusy = False
        Threading.Thread.Sleep(1000)
        Application.DoEvents()
    Loop

So I tried this code but all this does is still just download the page's source.

Using client As New WebClient()
        client.Headers("User-Agent") = "Mozilla/4.0"
        client.Credentials = New NetworkCredential("Username", "P@sword")
        client.Credentials = CredentialCache.DefaultCredentials ' << if Windows Authentication
        Dim content As String = client.DownloadString("https://www.fedex.com/insight/manifest/download.jsp?VIEW=/Outbound_View")
        Console.WriteLine(content.Substring(0, 15))
    End Using

I checked the webpage's source again to try to find a different url but also could not find anything else. I was wondering if it would be easier to download using WebBrowser.Navigate and then suppress the popups. Is there away to suppress or get rid of the download popups in vb? I am just not having much success with the WebClient. Thanks for all the help as I am still pretty new at vb.net!

Justin14
  • 11
  • 2
  • You should be able to download it directly into a file. Save it as a byte array and then format it, transfer it into the folder using a webclient or httpwebrequest. – Kat Feb 10 '15 at 16:44
  • 1
    On a side note, I hope you realize that using DoEvents() can be scary in both VB and C#. Well verse yourself so you don't make too many mistakes: http://stackoverflow.com/questions/5181777/use-of-application-doevents – Kat Feb 10 '15 at 16:45
  • My problem is that I am not actually downloading the file, I just navigate to the webpage and that, then triggers an automatic download. However; the download is not completely automatic because of the popups :( Thanks for the heads up on DoEvents()! – Justin14 Feb 10 '15 at 17:40
  • Maybe you should look into downloading the file without the webbrowser, since it seems that's what you're looking for? You want the GUI out of it? I would suggest looking into a WebClient example of DownloadFile. Might be what you need! https://msdn.microsoft.com/en-us/library/system.net.webclient.downloadfile(v=vs.80).aspx – Kat Feb 10 '15 at 18:20
  • I tried downloading the file using WebClient.UploadVaules(address as string, NameValueCollection) However; it just downloaded the source of the webpage not the data I am looking for! – Justin14 Feb 10 '15 at 18:37
  • No no, don't do upload values. Look at this awesome example page: http://www.dotnetperls.com/webclient-vbnet But, you might also need a different URL ! I'd bet good money that the FedEx SDK has an option for that URL for just the raw data or for information in general. I suggest looking up some documentation, and for a company that big they're sure to have some. – Kat Feb 10 '15 at 19:11
  • I edited my question to show what I have tried. I tried using WebClient.DownloadString but still with out any success... – Justin14 Feb 11 '15 at 13:54

0 Answers0