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();
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; } }}
and there is form with dropdownlist with values and there is event
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Image1.ImageUrl = "Handler.ashx?id=" + DropDownList1.SelectedItem.Value; GetImageInfo(DropDownList1.SelectedItem.Value);
}
application is running with no error but i have one question that howcome in
"id"(in handler code)value gets 1,2 or 3 (as per dropdownlist items) as qhen i run the url on browswer have only
http://localhost:60686/server_controls/2.%20image_retrieving_database.aspx" then how it gets value fetched in
context.Request.QueryString["id"];
pls tell regards