tags:

views:

99

answers:

2

My ImageHandler.ashx is not working when the webpart is calling it. any ideas on what is the correct way on calling or adding a handler in sharepoint? Thanks in advance

Here My ImageHandler.ashx code

    byte[] buffer = (byte[])image.ImageData;
    context.Response.ContentType = "image/jpeg";
    context.Response.OutputStream.Write(buffer, 0, buffer.Length);

In my webpart

imgcontrol.ImageUrl = "ImageHandler.aspx?id=1";
A: 

Check the Location where you have Deployed the ImageHandler.ashx. I have done similar thing in past and was able to get it working without any issues.

I deployed to _Layouts folder

imgcontrol.ImageUrl="_Layouts\x.ashx";

I assume that the code in your question is just a typo.

imgcontrol.ImageUrl = "ImageHandler.ashx?id=1";
Kusek
A: 

this is a fragment from my own image handler that we use to load map pins in a sharepoint mapping webpart. We load the image, modify it, then return it.

Bitmap bmpPin = Bitmap.FromFile("myImageFile.jpg") as Bitmap
using (MemoryStream memStream = new MemoryStream())
{
   this.m_Context.Response.ContentType = "image/png";
   bmpPin.Save(memStream, ImageFormat.Png);
   memStream.WriteTo(context.Response.OutputStream);
   memStream.Close();
   memStream.Dispose();
}
bmpPin.Dispose();
Muad'Dib