Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
return default image in image handler
Hazel Mahmud
Mar 16 2015 11:58 PM
550
Reply
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();
}
}
}
TQ in advance
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
how to access C# application remotly
Formatting in excel failing with C Sharp