Is it possible to use a embedded resource with WebBrowser?

  • Thread starter Thread starter LEM
  • Start date Start date
L

LEM

Hi,

I use a Webbrowser component to display a page that
has been generate dynamically from my C# program.
This page contains some images that are displayed using
HTML code like this:
<img src="person.gif">

person.gif is an image that is located in my bin folder.

What I would like to do is to use an embedded picture resource
instead, so I don't have to include the picture in my destination
folder.

Is that possible? If it is, what syntax should I use to display an image?

Thanks
 
Your image would be something like this:

string strSrc =
global::YourCustomNamespace.Properties.Resources.NameOfImageYouLoaded;

Then,
<img src="<%=strSrc>">

(line above is untested. not sure about the placement of quotes and such.)

Hope it helps.
 
Thanks for your help.

Almost there... I get an error at your first line:
Cannot implicitly convert type 'System.Drawing.Bitmap' to 'string'

Not sure if I need to cast something or not.
 
Hi,

I use a Webbrowser component to display a page that
has been generate dynamically from my C# program.
This page contains some images that are displayed using
HTML code like this:
<img src="person.gif">

person.gif is an image that is located in my bin folder.

What I would like to do is to use an embedded picture resource
instead, so I don't have to include the picture in my destination
folder.

Is that possible? If it is, what syntax should I use to display an image?

Thanks

Hi,

You can extract your images into temp files and then use the temp
paths in your webpage
 
Ah yes! That would be right.

You won't be able to get a string path to an embedded resource. The code I
showed you will provide you with an embedded resource, but your HTML requires
a string path to a file.

If this were a windows form and you were trying to fill a PictureBox Image,
this would work.

Since you are dealing with HTML, I don't think you can do this.
 
Now here is a thought: Instead of linking to some file, you may be able to
drop a PictureBox onto your webform. If so, then in your code, you can assign
the Image using your embedded resources!

Always 2 ways to skin a cat (though I'm not really interested in skinning
any cats).
 
try navigating to

res://ApplicationPath/ApplicationName.exe/myembeddedresourcename.png



--
Pete
=========================================
I use Enterprise Core Objects (Domain driven design)
http://www.capableobjects.com/
=========================================
 
Back
Top