I'm trying to load an image from a Stream. The image is saved in a DB. I have a page called RetrieveImage.aspx that will read and output the image as follows... (Note: This is in the Page_Load event)
Dim bytImage As Byte()
bytImage = CType(dr("imgImage"),
Byte()) ' dr is the SqlDataReader that contains the image
Response.ContentType = "image/jpeg"
Response.BinaryWrite(bytImage)
Response.End()
Another page contains an ASP:Image control. In the Page_Load() event I have the following code...
I have also included the following code in the Page_PreRender() event of the page that contains the image control.
Dim frm As New HtmlForm()
frm = Me.Page.Form
frm.Enctype = "multipart/form-data"
As far as I can see, everything is setup properly, however, the image never loads. When I put a breakpoint in the Page_Load() event of RetrieveImage.aspx, it is never called.
Your sample looks great and I will check it out, but that really doesn't answer the question as to why in my case, the ImageURL does not resolve to my "RetrieveImage.aspx". I would assume that during the Page_Load() event that it would try to resolve the
Url and hit the breakpoint that I've set in my RetrieveImage.aspx page.
As I said, your sample code looks great, but the page containing the <asp:image> control(s) is no simpler than in my example. I'm trying to find out why the call to RetrieveImage.aspx never takes place.
Your sample looks great and I will check it out, but that really doesn't answer the question as to why in my case, the ImageURL does not resolve to my "RetrieveImage.aspx". I would assume that during the Page_Load() event that it would try to resolve the
Url and hit the breakpoint that I've set in my RetrieveImage.aspx page.
As I said, your sample code looks great, but the page containing the <asp:image> control(s) is no simpler than in my example. I'm trying to find out why the call to RetrieveImage.aspx never takes place.
Thanks
</div>
There can be many reasons the path of the page that you have put in
Also if you can incorporate mine into urs it wud be better since thats a working example and what do u mean by "no simpler than in my example"?
As it turns out, using an HTTPContext handler instead of an ASPX (web form) to retrieve the image, did the trick.
All I meant is that in both your example and my example, I was setting the URL to an ASPX page that would load the binary image. The "source" page with the <asp:image> control was not the problem. It was getting to the delivery method.
Thanks for your replies (and I will still check out your sample...you can never know enough about this stuff!).
As it turns out, using an HTTPContext handler instead of an ASPX (web form) to retrieve the image, did the trick.
ASPX will definately work provided you disable caching of that page as I have suggested in previos post and also my example hence it works so smoothly without HTTP handler
hampdentech
Member
57 Points
15 Posts
Loading image from stream
Mar 12, 2009 02:11 PM|LINK
I'm trying to load an image from a Stream. The image is saved in a DB. I have a page called RetrieveImage.aspx that will read and output the image as follows... (Note: This is in the Page_Load event)
Another page contains an ASP:Image control. In the Page_Load() event I have the following code...
where ID = the primary key to load the image.I have also included the following code in the Page_PreRender() event of the page that contains the image control.Dim frm As New HtmlForm() frm = Me.Page.Form frm.Enctype = "multipart/form-data"As far as I can see, everything is setup properly, however, the image never loads. When I put a breakpoint in the Page_Load() event of RetrieveImage.aspx, it is never called.
What could I be missing?
Thanks,
Bob
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Loading image from stream
Mar 12, 2009 02:35 PM|LINK
Refer my article for working code
http://www.aspsnippets.com/post/2009/02/21/Display-Images-from-Database-using-ASPNet.aspx
Contact me
hampdentech
Member
57 Points
15 Posts
Re: Loading image from stream
Mar 12, 2009 05:22 PM|LINK
Your sample looks great and I will check it out, but that really doesn't answer the question as to why in my case, the ImageURL does not resolve to my "RetrieveImage.aspx". I would assume that during the Page_Load() event that it would try to resolve the Url and hit the breakpoint that I've set in my RetrieveImage.aspx page.
As I said, your sample code looks great, but the page containing the <asp:image> control(s) is no simpler than in my example. I'm trying to find out why the call to RetrieveImage.aspx never takes place.
Thanks
Gary Frank
Participant
919 Points
339 Posts
Re: Loading image from stream
Mar 12, 2009 05:30 PM|LINK
Try using an HTTP handler instead of a web page to get your image. Here's a post that contains code that does it:
http://forums.asp.net/t/1385028.aspx
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Loading image from stream
Mar 12, 2009 05:46 PM|LINK
There can be many reasons the path of the page that you have put in
Also if you can incorporate mine into urs it wud be better since thats a working example and what do u mean by "no simpler than in my example"?
Contact me
hampdentech
Member
57 Points
15 Posts
Re: Loading image from stream
Mar 12, 2009 05:46 PM|LINK
Hi Gary,
Thanks for the reply. That did the trick!!
Bob
hampdentech
Member
57 Points
15 Posts
Re: Loading image from stream
Mar 12, 2009 05:50 PM|LINK
As it turns out, using an HTTPContext handler instead of an ASPX (web form) to retrieve the image, did the trick.
All I meant is that in both your example and my example, I was setting the URL to an ASPX page that would load the binary image. The "source" page with the <asp:image> control was not the problem. It was getting to the delivery method.
Thanks for your replies (and I will still check out your sample...you can never know enough about this stuff!).
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Loading image from stream
Mar 12, 2009 06:00 PM|LINK
Finally I think ur code is not hiting breakpoint because its calling page is browser cache
If you add this to ur RetreiveImage.aspx page load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
And then press CTRL + F5 ur code shud work
Contact me
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Loading image from stream
Mar 12, 2009 06:02 PM|LINK
ASPX will definately work provided you disable caching of that page as I have suggested in previos post and also my example hence it works so smoothly without HTTP handler
Contact me