priya gupta

priya gupta

  • NA
  • 294
  • 0

Using HttpHandler for Images - can't print images frm chrome

Jun 19 2014 3:39 AM
Hi,
I'm using an HttpHandler to display images from memory ... which is working fine.
The image is displayed as a .png format in a popup window.
My problem is printing the image from chromeWeb Browser using the popup menu displayed after doing a right-click, selecting 'Print Picture'.
A blank page is being printed ... i.e. No Image, just the url and date on the bottom of the page and the page number on the top.
I have also tried this with the image formatted as .jpg, with the same result.
Neither 'Print Picture' or 'E-mail Picture' is working properly. With E-mail, an email is created, but no image.
The Image Control's ImageUrl="~/ImageHandler.ashx"
The code used to update the image in the ImageHandler is located in the ProcessRequest function:
if (context.Request.QueryString["z"] != null)
{
SecureQueryString qs = new SecureQueryString(context.Request.QueryString["z"]);
if (!String.IsNullOrEmpty(qs["icontable"]) && !String.IsNullOrEmpty(qs["iconcolumn"]) && !String.IsNullOrEmpty(qs["iconid"]))
{
ServiceClient webservice =WCF.GetService();
byte[] imgReceipt;
try
{
SQLCommand cmd = new SQLCommand();
cmd.StoredProcedureName = "JSN_GENERIC_ICON_LOADER";
cmd.Parameters = new List<SQLParameter>();
cmd.Parameters.Add(new SQLParameter() { ParameterName = "@TABLENAME", Value = qs["icontable"] });
cmd.Parameters.Add(new SQLParameter() { ParameterName = "@COLUMNNAME", Value = qs["iconcolumn"] });
cmd.Parameters.Add(new SQLParameter() { ParameterName = "@ROWID", Value = int.Parse(qs["iconid"]) });
using (DataSet ds = webservice.ExecuteDataSet(cmd))
{
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].Rows[0];
imgReceipt = DBHelper.GetDBImage(dr, "ICONDATA");
MemoryStream stream = new MemoryStream(imgReceipt);
if (stream.Length > 1)
{
context.Response.ContentType = "image/png";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
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);
}
}
}
}
}
catch
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "File Not Found";
context.Response.Flush();
}
finally
{
qs = null;
}
}
else
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Invalid Request";
context.Response.Flush();
}
}
I would greatly appreciate any thoughts on how to get print to work.
Thanks.
Priya