Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to embed images in a Web Control Library

Status
Not open for further replies.

koraykazgan

Programmer
Jan 11, 2005
17
DE
Hi there,

I am programming a Web Control Library in C#. I have included my images for my custom button control in the project, and wrote the html code to render the control. But when I compile the project to a DLL I have to copy the used images into a folder, to be able to use it.

I figured out, that I can set the build action property of the images to Embedded Resource. So, my question is where are the images? And how can I use the images in the compiled resource in my html code?

Thanks for your help,
bye...
 
Take a look at the Assembly.GetManifestResourceStream() method. You'll need to pass the full name to the resource.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
ASP.NET provides two types of custom controls.
One is "user control" which in fact of functionality falls somewhere between a server control and an include file.
A user control has its own process space but is compiled on demand just like any ASP.NET page.
In other words, the control is a text file rather than a compiled DLL.
The 2nd type is a "custom server control" and I think you are talking about it.
An ASP.NET custom server control is precompiled and lives in a DLL on the server. It has properties and methods and almost always renders HTML, but it could perform some behind-the-scenes, nonvisual actions.
The embeeded images in the control are part of the control (DLL) and you can access them at run time when you need.
You show that image on a page in the overloaded Render() method of the control, for example.
First of all, retrieve the image from the control, save it in a file and render it using the HTML tags:
Code:
public override Render( ref output System.Web.UI.HtmlTextWriter)
{
	// save image1 on "image1.bmp"
	Bitmap bmp = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("myassembly.image1.bmp"));
	bmp.Save("myimage1.bmp"); // or with different format
	output.RenderBeginTag(HtmlTextWriterTag.Img);
	output.AddAttribute(HtmlTextAttribute.src,"myimage1.bmp");
	
}
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top