Click to See Complete Forum and Search --> : Image Handler ashx file, can i write this better?


mcmcom
March 18th, 2006, 08:20 PM
a bit of background:
images are located on network share disk
the code below is working great. I just want to know if its as fast as possible, also about any issues with memory. the images can be up to 64 meg but will probably be approx 5-10mb.

thanks



public class ImageHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
ImageInfo i = (ImageInfo)SessionManager.Current.ImageList[SessionManager.Current.CurrentPosition];
string fileName = i.FileName.ToString();
string tId = i.TrackingId.ToString();
FileStream myFile = new FileStream((string)ConfigurationSettings.AppSettings["uploadPath"]+ "\\" + tId +"\\" + fileName, FileMode.Open);
long nFileLen = myFile.Length;
byte[] imgData = new Byte[nFileLen];
myFile.Read(imgData, 0, int.Parse(nFileLen.ToString()));
//write image out
context.Response.ContentType = "image/jpeg";
context.Response.OutputStream.Write(imgData, 0, int.Parse(nFileLen.ToString()));
myFile.Close();
}

public bool IsReusable
{
get { return true; }
}
}