there is one handler <%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Web; using System.IO; using System.Data.SqlClient;
public class Handler : IHttpHandler { public string GetConnectionString() { return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString; } public void ProcessRequest (HttpContext context) { string id = context.Request.QueryString["id"]; if (id != null) { MemoryStream memoryStream = new MemoryStream(); SqlConnection connection = new SqlConnection(GetConnectionString()); string sql = "SELECT * FROM TblImages WHERE Id = @id"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@id", id); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); //Get Image Data byte[] file = (byte[])reader["Image"]; reader.Close(); connection.Close(); memoryStream.Write(file, 0, file.Length); context.Response.Buffer = true; context.Response.BinaryWrite(file); memoryStream.Dispose(); }} public bool IsReusable { get { return false; } }}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Image1.ImageUrl = "Handler.ashx?id=" + DropDownList1.SelectedItem.Value; GetImageInfo(DropDownList1.SelectedItem.Value); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)