Copy image from webbrowser to clipboard - vb.net

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'.

Related

ACCESS VBA Picture saved as OLE OJECT used as Picture property for custom command bar

I have some custom popup menus in my app and i am tired of using the .FaceID property just to set some "not so relevant" images form my commands. What i want to do is to get some pictures saved in a local table OLE-OBJECT field and display those instead of the MS pictures.
The controls of commandbar object have .Picture and .Mask properties which work just fine if i load a file from the hdd into a IPictureDisp object using stdole.LoadPicture, but i don't want to have hundres of small files in my app folder.
So, my question is: is there a way i can get the picture saved in the local table to become a IPictDisp. I can get it's byte array just fine, but i found no way of converting that into something that the Commandbar button can recognize.
Thank you for any help.

accessing the controls on a webpage I have just opened

I have a piece of code that opens a web page in my default browser (IE10).
Dim url As String
url = "http://www.google.com"
Process.Start(url)
How do I then pass a value to the text box on that page. I am using google as an example. I am using VS2013, VB and asp.net
Thanks
This video should give you all of the information that you need. It is a tutorial on creating an automatic yahoo login from vb, but it will show you how to pass values to a textbox on a webpage, as well as working with other webpage controls.
NOTE: You will need to navigate to the page and view source to get the id of the controls

Download file from WebBrowser Control via WebClient

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

using ppDisp to take control of popup windows in userform

I have setup a userform1 to browse an intranet using web browser controls in VBA/Excel. The problem I am having is that when the user initiates a popup through the web browser control, that popup runs in IE by default, outside of the scope of the web browser control, and therefore doesnt contain the correct session data in the popup. This popup initiates from a dropdown box, onchange command and then inserts the input from the popup back into a web form on the page. The code below intercepts the popup event and lets you handle it, by transferring it to say, userform2
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim frm As UserForm2
'Dim ppDisp As Object
Set frm = New UserForm2
Set ppDisp = frm.WebBrowser1.Application
frm.Show
End Sub
Problem is, it gets stuck right now on frm.show, when I pause, and doesnt seem to be actively transferring over the web page correctly into userform2. I'm not sure where my logic is wrong here, any advice would be helpful. Most guides have shown:
Set ppDisp = frm.WebBrowser1.object
But I cant find that in the object browser anywhere, and doing .object bombs out, as error 438: object doesnt support this property or method. But everything I could find on this so far shows using .object.
for anyone reading this, VBA wont support this method as the above says. It works perfectly in .net and I would assume then, vb6

Get the Document.Url of a WebBrowser

Programming Environment: Visual Studio 2010
Programming Language: VB.NET
I have a tabbed web-browser that I add dynamically, I Dim the the web-browser every-time the user clicks the New Tab button, like this: browser = New WebBrowser() and give it a name based on the tab count, e.g. browser2, if there are 2 tab pages. So my question is - about time - that how would I get the Url of the WebBrowser, I have tried Dim UrlString As String = CType(tabMain.SelectedTab.Controls.Item(browser.Name), WebBrowser).Url.ToString But, correct me if I am wrong, I found that WebBrowser isn't classed as a Control, and the reason why I think this is because:
This gives me an exception: Object reference not set to an instance of an object.
So I tried looping through the controls in the tabMain.SelectedTab and found that the WebBrowser(browser) isn't included in the collection. The code I used to loop was:
For Each ctrl As Control In Me.tabMain.SelectedTab.Controls
MsgBox(ctrl.Name)
Next
Tried looping through all the Parent controls, but no sign of the WebBrowser showing up. Hope this is enough information =P
Thanks in advance.
UPDATE: Figured out the problem, really stupid, and my theory was bullshit too =P. Just ignore =] lol
try this.
Dim UrlString As String = CType(tabMain.Controls.Item(0), WebBrowser).Url.ToString
I assume tabMain is the name of the TabControl. If this is true and each tab has a WebBrowser Control in it then it should work.