<%@ WebHandler Language="C#" Class="right7" %>using System;using System.IO;using System.Data;using System.Data.SqlClient;using System.Configuration;using System.Web;public class right7 : IHttpHandler {public void ProcessRequest (HttpContext context) {string branchid = "";//if(context.Session["branchid"]!=null)if (context.Request.QueryString["branchid"] != null) branchid = context.Request.QueryString["branchid"];elsethrow new ArgumentException("No parameter specified");context.Response.ContentType = "image/jpeg";Stream strm = ShowImage(branchid);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);}//context.Response.BinaryWrite(buffer) }public Stream ShowImage(string branchid){SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["transfer"].ConnectionString);string sql = "SELECT imgright7 FROM tblImages WHERE BranchId = @BranchId";SqlCommand cmd = new SqlCommand(sql, con);cmd.CommandType = CommandType.Text;cmd.Parameters.AddWithValue("@BranchId", branchid);con.Open();object img = cmd.ExecuteScalar();try{return new MemoryStream((byte[])img);}catch{return null;}finally{con.Close();}}public bool IsReusable {get {return false;}}}
using System.Data;using System.Data.SqlClient;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class right7image : System.Web.UI.Page{SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["transfer"].ConnectionString);string branchid = "";protected void Page_Load(object sender, EventArgs e){branchid = Session["UserName"].ToString();if (IsPostBack == false){Image1.ImageUrl = "right7.ashx?BranchId=" + branchid;Image2.ImageUrl = "right7old.ashx?BranchId=" + branchid;} }protected void LinkButton1_Click(object sender, EventArgs e){Response.Redirect("Images.aspx");}protected void Button1_Click(object sender, EventArgs e){//update//1st copy using ptrSqlCommand cmdptr = new SqlCommand("copyprevimgr7", con);cmdptr.CommandType = CommandType.StoredProcedure;con.Open();cmdptr.Parameters.AddWithValue("@BranchId", branchid);cmdptr.ExecuteNonQuery();con.Close(); //2nd newlybrowse once updateleft1imageSqlCommand cmdupdate = new SqlCommand("updateright7", con);cmdupdate.CommandType = CommandType.StoredProcedure;con.Open();cmdupdate.Parameters.AddWithValue("@BranchId", branchid);if (FileUpload1.HasFile){FileInfo left1info = new FileInfo(FileUpload1.PostedFile.FileName.Trim());byte[] left1content = new byte[left1info.Length];FileStream left1stream = left1info.OpenRead();left1stream.Read(left1content, 0, left1content.Length);left1stream.Close();cmdupdate.Parameters.AddWithValue("@imgright7", left1content);} cmdupdate.Parameters.AddWithValue("@noter7", TextBox1.Text); if (cmdupdate.ExecuteNonQuery() != 0){con.Close();clsdatasettransfer.ShowAlertMessage("Updated.....");TextBox1.Text = "";System.Threading.Thread.Sleep(2000);Image1.ImageUrl = "right7.ashx?BranchId=" + Session["UserName"].ToString();Image2.ImageUrl = "right7old.ashx?BranchId=" + Session["UserName"].ToString();}else{ clsdatasettransfer.ShowAlertMessage("Updatefailed");}}}