hrolsons
asked on
Load .jpg in webbrowser control
Does anyone know how to load a .jpg file into a webbrowser, from a local file on the hard disk?
This doesn't work:
WebBrowser2.Navigate ("C:\image.jpg")
But, I can go to regular Internet Explorer and type "C:\image.jpg" in the address bar and it comes up fine.
This doesn't work:
WebBrowser2.Navigate ("C:\image.jpg")
But, I can go to regular Internet Explorer and type "C:\image.jpg" in the address bar and it comes up fine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Still not working.
Try:
WebBrowser2.Navigate "file://C:\image.jpg"
WebBrowser2.Navigate "file://C:\image.jpg"
ASKER
No luck:
Navigation to the webpage was canceled
Navigation to the webpage was canceled
I've tried it myself and for me,
WebBrowser2.Navigate "file://C:/image.jpg"
worked. Little odd and non-conforming but hey, it's MS.
WebBrowser2.Navigate "file://C:/image.jpg"
worked. Little odd and non-conforming but hey, it's MS.
ASKER
Fortunately, it's not vital to my project(would be nice though), but I can't get it to work trying all of the conventions above.
What if you try to load it this way?
Dim html As String
html = "<img src=" & Chr(34) & "file://localhost/C:/Users /Mike/Pict ures/Ameri canFlag.jp g" & Chr(34) & " align=" & Chr(34) & "center" & Chr(34) & "/>"
WebBrowser1.DocumentText = html
Dim html As String
html = "<img src=" & Chr(34) & "file://localhost/C:/Users
WebBrowser1.DocumentText = html
ASKER
"Object doesn't support this property or method"
ASKER
Interesting, out of frustration, I moved the file from it's long path to C:\image.jpg and it worked. So then I thought it might be a backslash,forward slash issue. But it actually turned out to be the fact that my W: drive is a mapped drive to my web server. Not sure why it doesn't like it, but that's a different subject all together.
Sorry...I'm working in VB.Net...try this:
Dim html As String
html = "<img src=" & Chr(34) & "file://localhost/C:/Users/Mike/Pictures/AmericanFlag.jpg" & Chr(34) & " align=" & Chr(34) & "center" & Chr(34) & "/>"
WebBrowser1.Navigate "about:blank"
While (WebBrowser1.Document Is Nothing)
DoEvents
Wend
With WebBrowser1.Document
.Open
.Write html
.Close
End With
ASKER
I'm going to shut down firewall & anti-virus to rule that out.