I have this code:
I'm trying to have my program download all the images (that contains "jpg") from a site.
Dim doc As IHTMLDocument2 = DirectCast(WebBrowser1.Document.DomDocument, IHTMLDocument2)
Dim imgRange As IHTMLControlRange = DirectCast(DirectCast(doc.body, HTMLBody).createControlRange(), IHTMLControlRange)
For Each img As IHTMLImgElement In doc.images
If img.nameProp.Contains("jpg") Then
imgRange.add(DirectCast(img, IHTMLControlElement))
imgRange.execCommand("Copy", False, Nothing)
Using bmp As Bitmap = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
'bmp.Save("test.gif", System.Drawing.Imaging.ImageFormat.Gif)
bmp.Save("MyImages")
End Using
End If
Next
WebBrowser1.Navigate("http://www.yahoo.com")
Getting an error on line 1 with System.NullReferenceException (Object reference not set to an instance of an object).