Download file from WebBrowser Control via WebClient - vb.net

I am using webBrowser control to login and fetching download link from an anchor tag. The link contains a dynamically generated .csv file (even this file is not accessible without login).
My download code looks like
Dim rLink = curElement.GetAttribute("href").ToString()
Dim myWebClient As New WebClient()
myWebClient.Headers.Add(HttpRequestHeader.Cookie, WebBrowser1.Document.Cookie)
myWebClient.DownloadFile(rLink, "report.csv")
Above code fires on DocumentCompleted event

Related

open mxd in arcobjects vb.net add in

I am trying to open an mxd in an ESRI ArcMap add-in using vb.net. The user starts with a blank mxd and runs a tool to open an mxd that is stored in a file. The mxd that is opened by the code has some feature layers and some graphics in the layout.
So far I have:
Dim mapdoc As IMapDocument = New MapDocumentClass()
mapdoc.Open("D:\__Test\LockItInPMAV.mxd")
The document opens because I can get its filename via:
MsgBox("Filename: " & mapdoc.DocumentFilename)
However the data view and layout view remain blank, they do not show the contents of the opened file.
How can I get the opened file to display in the current ArcMap session?
Thanks,
Luke.
I'm working in C#. I'm not sure if you can load an mxd after it is loaded.
You would either need to load a new arcmap instance and pass the mxd name as a parameter:
var expanPath = Environment.GetEnvironmentVariable(Properties.Settings.Default.arcmapLaunchPath,
EnvironmentVariableTarget.Machine);
string Cmd = string.Format(#"{0}\arcmap.exe", expanPath);
ProcessStartInfo startInfo = new ProcessStartInfo(Cmd);
startInfo.Arguments = Properties.Settings.Default.MxDPath;
Process.Start(startInfo);
Process.GetCurrentProcess().Kill();
The MXD holds so much details on how the instance of arcmap operates that it is not easy to reload it. Our esri contractor confirmed this.
I am told that Pro, has changed this completely.

Load webbrowser content into another webbrowser control

I have such situation:
1) One form named 'frm_iexplorer' with webbrowser and loaded document into it.
2) One class named 'PrintHTMLDocument' which creates webbrowser dynamically.
I would like to load a same document into second, dynamically created webbrowser from first webrowser.
My approach in class is like:
Dim ie As New InternetExplorer
ie.Navigate(frm_iexplorer.WebBrowser1.document())
... don't work.
frm_iexplorer is not accessible.
How to do this?

Copy image from webbrowser to clipboard

I need to copy an image from a webbrowser control to my clipboard, because the image changes on every reload, and I tried to get the "src"-attribute and changing my picturebox.imagelocation to that, but the image on the picturebox differed from the picture on the webbrowser control.
I'm trying to automate a web service, and it requires a captcha to be filled out, and it changes every time the page is loaded, that's why I need to get the one that is currently displayed.
Assuming you are using Windows Forms (need to change the way to get document if you use WPF) and the user did not block clipboard access in IE zone settings
Dim doc As IHTMLDocument2 = DirectCast(webBrowser1.Document.DomDocument, IHTMLDocument2)
Dim body As IHTMLElement2 = DirectCast(doc.body, IHTMLElement2)
Dim imgRange As IHTMLControlRange = DirectCast(body.createControlRange(), IHTMLControlRange)
Dim image As IHTMLControlElement = DirectCast(DirectCast(doc, IHTMLDocument3).getElementById(sImgID), IHTMLControlElement)
imgRange.add(image)
imgRange.execCommand("Copy", False, Nothing)
Pseudo code:
For each element by tag 'img'. Get the 'src' attribute. Fire up an instance of HttpWebRequest or use WebClient.DownloadFile for the source.
You will need to do some trickery determining where the source is in relation to the url. For instance the src could be '/img/pony.jpg', in which case you'll need to get the url's root from the WebBrowser control to make it 'http://mylittle.com/img/pony.jpg'.

C# webbrowser control: page opens new window but it won't work

I use a webbrowser control (in C# - latest version of visual studio and .NET) to allow me to read and write data to a specific web page. Everything is OK until I reach the point that the page attempts to open a pdf document in a new window (the page contains javascript code).
The new window opens OK on my IE. But nothing appears when the webbrowser control opens the new window...
I've tried setting firefox as my default browser to see if it makes any difference but no good came out of it. The webbrowser control still opened IE.
I've tried catching the event of the new window and refer the url to another webbrowser control... no success again!
How can I get the pdf document? And why would the new window open but not display the pdf?

How can I open an external browser window and refresh it inside a VB.net application?

We have an existing VB.net application. Upon an event, we need to open a browser window. I'm able to open the browser window like this:
System.Diagnostics.Process.Start("http://s3web01/suggestions?item=" + strItem + "&co=" + strOrder)
Upon another event, we need to refresh the browser window with different parameters for strItem and strOrder.
If I call the same code above, it opens a new tab in the browser window. Is there any way to refresh the same browser window that was previously opened?
Add a reference to the following COM libraries: Microsoft Internet Controls (namespace ShDocVw), and Microsoft HTML Object Library (namespace mshtml).
Then you can create a new IE instance:
Dim IE As ShDocVw.InternetExplorer = New ShDocVw.InternetExplorer
and control it like so: IE.Navigate("http://blah.com")
refresh it like so: IE.Refresh
etc