No solution yet!!!
I`m following all the steps, but somewhere is a problem and I can`t figure it out :(
So, I`m going to specife my program structure in details, so maybe someone will now what is wrong with it.
I have a table PRODUCTS which has foreign key ImageFK on IMAGE table.
IMAGE table ID is nchar(10), also ImageFK in PRODUCTS is nchar(10).
In one aspx page I have a listview of my products with some records (f.e. Product Name, Product Price..) and I want also to show my product image.
So the query which is bind to this listview go like this:
var query=(from x in Products
select new
{
x.Id,
x.ProductName,
x.ProductPrice,
x.ImageFK
}).ToList();
return query;
Everything is shown perfectly, beside Image :(
I`ve created ashx page "ImageShow.ashx", the code is shown below: //
public class ImageShow : IHttpHandler
{
public Stream ShowEmpImage(string id)
{
using (DCKlaseDataContext dc = new DCKlaseDataContext())
{
var queryImage = (from x in dc.Images
where x.Id == id
select x).FirstOrDefault();
return new MemoryStream(queryImage.Image.ToArray());
}
}
public void ProcessRequest(HttpContext context)
{
string id = context.Request.QueryString["ImageFK"].ToString();
context.Response.ContentType = "image/jpeg";
Stream strm = ShowEmpImage(id);
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}
And final step is on my image field in my aspx page, to add image url (which is this ashx page):
<asp:image id="img_1" runat="server" imageurl="ImageShow.ashx?ImageFK=<%# Eval("ImageFK") %>" xmlns:asp="#unknown" />
And when I build the program, it show error on
return new MemoryStream(queryImage.Image.ToArray());
with message:
Object reference not set to an instance of an object.
Anyone?!
Thank you..