Is it possible to use a embedded resource with WebBrowser?

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
 
J

jp2msft

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

LEM

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

Ignacio Machin ( .NET/ C# MVP )

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
 
J

jp2msft

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

jp2msft

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).
 
P

Peter Morris

try navigating to

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



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top