what code to add and where do i add code that retrieve default image in image handler code that i've attached below :
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Int32 ID;
if (context.Request.QueryString["nopkj_cari"] != null)
ID = Convert.ToInt32(context.Request.QueryString["nopkj_cari"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpg";
Stream strm = DisplayImage(ID);
byte[] buffer = new byte[2048];
int byteSeq = strm.Read(buffer, 0, 2048);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 2048);
}
}
public Stream DisplayImage(int ID)
{
using (AseConnection persisConn = ClassConn.GetPersisConnection())
{
persisConn.Open();
AseCommand selcmd = new AseCommand("select gambar=f630gambar from t630picture where f630nopkj=" + ID, persisConn);
persisConn.Open();
object theImg = selcmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])theImg);
}
catch
{
return null;
}
finally
{
persisConn.Close();
}
}
}
{
public void ProcessRequest(HttpContext context)
{
Int32 ID;
if (context.Request.QueryString["nopkj_cari"] != null)
ID = Convert.ToInt32(context.Request.QueryString["nopkj_cari"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpg";
Stream strm = DisplayImage(ID);
byte[] buffer = new byte[2048];
int byteSeq = strm.Read(buffer, 0, 2048);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 2048);
}
}
public Stream DisplayImage(int ID)
{
using (AseConnection persisConn = ClassConn.GetPersisConnection())
{
persisConn.Open();
AseCommand selcmd = new AseCommand("select gambar=f630gambar from t630picture where f630nopkj=" + ID, persisConn);
persisConn.Open();
object theImg = selcmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])theImg);
}
catch
{
return null;
}
finally
{
persisConn.Close();
}
}
}
TQ in advance
Hazel MahmudPosted Mar 22, 2015, 12:03 AM
Rahul BansalPosted Mar 17, 2015, 4:37 AM
HttpContext.Current.Server.MapPath
Hazel MahmudPosted Mar 17, 2015, 3:44 AM
Rahul BansalPosted Mar 17, 2015, 12:56 AM
try after object theImg = selcmd.ExecuteScalar();
if (theImg==null)
{
string filename = "../Images/no_photo.jpg";
byte[] imageByte = System.IO.File.ReadAllBytes(context.Server.MapPath(filename));
return new MemoryStream((byte[])imageByte);
}
else{return new MemoryStream((byte[])theImg);}