Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<%@ WebHandler Language="C#" Class="Handler" %>

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

public class Handler : IHttpHandler {

SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["Drawing1"].ConnectionString) ;
SqlCommand cmd;

public void ProcessRequest (HttpContext context)
{

cmd = new SqlCommand("select Img from Service_Name where Service_Id=1002", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
context.Response.ContentType = "image/png";//use ur image type
context.Response.BinaryWrite((byte[])reader["Img"]);
}
con.Close();
}

public bool IsReusable {
get {
return false;
}
}

}


page only contains <asp:Image ID="Image1" Width="200px" Height="200px" runat="server" ImageUrl="~/Handler.ashx"/>

and when i see source after execution the image shows "The image cannot be shown as it contains error"
Posted
Updated 22-Sep-13 3:52am
v2

1 solution

Check your image: it may be the way you inserted them, rather than how you extract it. This may help: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900