In a previous entry I have shown, how to store images to a database table. Now I will show you how to retrieve it and show it on a ASP.Net Image control. There is no straight forward method showing it like “ImageControl.Image = ImageStream….” How ever it can be achieved using a Generic Handler.
Add a ‘Generic Handler’ to your ASP.Net web application. And in this example I will name it as ‘getImageFromDB.ashx’. By default IHttpHandler will be implemented. (ProcessRequest and IsReusable methods will be implemented). And I will add another method called ‘GetImage’ and alter the ‘ProcessRequest’ method. And the finished handler should similar to this:
And you can call the handler and display the image, using the following syntax :