ASP.NET Embedded Resources

G

Grant Harmeyer

I have a project where I am required to embed a few images and CSS files in
the assembly (v1.1) and read them out at runtime. I know that this can be
done using an HttpHandler/.axd file (like the one used for FreeTextBox
http://www.freetextbox.com), but I've never tried this before. Does anyone
have any sample code for this? I know they've made this much easier in 2.0.
 
G

George Ter-Saakov

This is a code that outputs static image from a array.
It's a regular aspx page and called like this <img src="renewSes.aspx">
You should be able easily modify it to output from resource file

George.

public class renewSes : System.Web.UI.Page
{

static byte [] gif =
{0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0x91,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x09,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x08,0x04,0x00,0x01,0x04,0x04,0x00,0x3b,0x00};

override protected void OnInit(EventArgs e)

{

Response.AddHeader("ContentType", "image/gif");

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.BinaryWrite(gif);

Response.End();

}


}
 
G

Grant Harmeyer

Yes, but that still doesn't use an HttpHandler to read the image or CSS from
the assembly as an embedded resource. For example, the FreeTextBox
WebControl has all of the images and such embedded into the assembly. Then
when the page is rendered, the webpage references the images like so:

<img
src="FtbWebResource.axd?a=FreeTextBox%2c+Version%3d3.1.5000.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d5962a4e684a48b87&r=FreeTextBoxControls.Resources.Images.OfficeMac.superscript.gif&t=632727198542727578"
/>

I would like to reference the images and CSS files that I use for themes to
be referenced in the same way.


George Ter-Saakov said:
This is a code that outputs static image from a array.
It's a regular aspx page and called like this <img src="renewSes.aspx">
You should be able easily modify it to output from resource file

George.

public class renewSes : System.Web.UI.Page
{

static byte [] gif =
{0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0x91,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x09,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x08,0x04,0x00,0x01,0x04,0x04,0x00,0x3b,0x00};

override protected void OnInit(EventArgs e)

{

Response.AddHeader("ContentType", "image/gif");

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.BinaryWrite(gif);

Response.End();

}


}
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top