sagar Bhosale

sagar Bhosale

  • NA
  • 179
  • 173.2k

Problem - how to display multiple image using ashx handler

May 20 2012 7:07 AM
<%@ WebHandler Language="C#" Class="ShowImage" %>

using System;
using System.Configuration;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;

public class ShowImage : IHttpHandler
{
 
  public void ProcessRequest (HttpContext context)
  {
  Int64 Sys_MTrxn_ID;
  if (context.Request.QueryString["id"] != null)
  Sys_MTrxn_ID = Convert.ToInt64(context.Request.QueryString["id"]);
  else
  throw new ArgumentException("No parameter specified");

  context.Response.ContentType = "image/jpeg";
  Stream strm = ShowEmpImage(Sys_MTrxn_ID);
  byte[] buffer = new byte[4096];
  int byteSeq = strm.Read(buffer, 0, 4096);

  while (byteSeq > 0)
  {
  context.Response.OutputStream.Write(buffer, 0, byteSeq);
  byteSeq = strm.Read(buffer, 0, 4096);
  } 
  }

  public Stream ShowEmpImage(Int64 Sys_MTrxn_ID)
  {
  DBHelper objDBHelper = new DBHelper();
  //string conn = ConfigurationManager.ConnectionStrings["MFBackOfficeConnectionString"].ConnectionString;
  string conn = objDBHelper.GetConnectionString();
  DataTable dt = new DataTable();
  SqlConnection connection = new SqlConnection(conn);
  //string sql = "SELECT Transaction_Image FROM t_manualtransaction WHERE Sys_MTrxn_ID = (select Sys_MTrxn_ID from t_manualtransaction where Sys_MTrxn_ID = " + Sys_MTrxn_ID.ToString() + ")";
  string sql = "SELECT Transaction_Image FROM T_ManualTrxnImages WHERE Sys_MTrxn_ID = (select Sys_MTrxn_ID from t_manualtransaction where Sys_MTrxn_ID = " + Sys_MTrxn_ID.ToString() + ")";
  //SqlCommand cmd = new SqlCommand(sql, connection);
  //cmd.CommandType = CommandType.Text; 
  SqlDataAdapter adpt = new SqlDataAdapter(sql, conn);
 
  adpt.Fill(dt);
  int ImgCnt = dt.Rows.Count;

  connection.Open();
  byte[] img = new byte[4096];
  for (int i = 0; i< dt.Rows.Count; i++)
  {
 
  byte[] storedImage = (byte[])dt.Rows[0]["Transaction_Image"];
  Image newImage;
  MemoryStream stream = new MemoryStream(storedImage);
  newImage = Image.FromStream(stream);
 
  }
 
  //object img = cmd.ExecuteScalar();
  //try
  //{
  //  return new MemoryStream((byte[])img);
  //}
  //catch
  //{
  //  return new MemoryStream();
  //}
  return new MemoryStream((byte[])img);
  connection.Close();
 
  }

  public bool IsReusable
  {
  get
  {
  return false;
  }
  }

}


--------------
plz help me this my code

Answers (1)