By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,281 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,281 IT Pros & Developers. It's quick & easy.

Auto Expand Images

P: n/a
I currently use the below code to display images from my database. Part of
what my site allows is for users to click on an image and I open up my
handler.ashx to display the image. Is there a way to make the image always
be displayed in full size? Users of my site dont realize that you can
either click the image to make it go full size or click the icon in the
lower right part of the image when you mouse over it to expand it.

public class Handler : IHttpHandler {

public bool IsReusable {

get {

return true;


public void ProcessRequest (HttpContext context) {

// Set up the response settings

context.Response.ContentType = "image/jpeg";

context.Response.Cache.SetCacheability(HttpCacheab ility.Public);

context.Response.BufferOutput = false;

// Setup the Size Parameter

// Setup the PhotoID Parameter

Int32 id = -1;

Stream stream = null;

string originalsize = "O";

if(context.Request.QueryString["Size"] != null &&
context.Request.QueryString["Size"] != "")


originalsize = context.Request.QueryString["Size"];

if (context.Request.QueryString["PhotoID"] != null &&
context.Request.QueryString["PhotoID"] != "")


id = Convert.ToInt32(context.Request.QueryString["PhotoID"]);

stream = PhotosService.GetPhoto(id, originalsize);




id = Convert.ToInt32(context.Request.QueryString["ProductID"]);

stream = PhotosService.GetFirstPhoto(id,
Convert.ToInt32(context.Request.QueryString["CompanyID"]), originalsize);


// Get the photo from the database, if nothing is returned, get the default
"placeholder" photo

if (stream == null)


stream = new
FileMode.Open, FileAccess.Read, FileShare.Read);


// Write image stream to the response stream

const int buffersize = 1024 * 16;

byte[] buffer = new byte[buffersize];

int count = stream.Read(buffer, 0, buffersize);

while (count 0)


context.Response.OutputStream.Write(buffer, 0, count);

count = stream.Read(buffer, 0, buffersize);


Aug 12 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.