public class ImageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { { System.Data.SqlClient.SqlDataReader rdr = null; System.Data.SqlClient.SqlConnection conn = null; System.Data.SqlClient.SqlCommand selcmd = null; try { //string path ="" conn = new System.Data.SqlClient.SqlConnection (System.Configuration.ConfigurationManager.ConnectionStrings["LiveAdsConnectionString"].ConnectionString); selcmd = new System.Data.SqlClient.SqlCommand("select Image from Adverts where AdvertsID=" + context.Request.QueryString["id"], conn); conn.Open(); rdr = selcmd.ExecuteReader(); while (rdr.Read()) { context.Response.ContentType = "image/jpg"; context.Response.ContentType = "image/png"; context.Response.WriteFile("/Images/" + rdr["Image"].ToString()); } if (rdr != null) rdr.Close(); } finally { if (conn != null) conn.Close(); } } } public bool IsReusable { get { return false; } } }
context.Response.WriteFile(Server.MapPath("~/Images/" + rdr["Image"].ToString()));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)