In my last post about SQL Server 2008 new feature File Stream (Saving and Retrieving File Using FileStream SQL Server 2008), we did an example of saving an image to the file stream and then retrieve it back and make it available for download.
The result of that example looks like as below.
But, one has to press the button to download the image file. One of my blog reader raise a point that he wants to display the same image instead of Get File button which is going to download.
So, in this post I will explain you, how can we rendered the image before actually downloading it and show that in the grid (Maybe as thumbnail, but this post will not discuss any thing about generating thumbnails).
Note : If you want to know. How to add files to the file stream please see my post Saving and Retrieving File Using FileStream SQL Server 2008
We will complete this goal by using HttpHandler. lets first alter our gridview.
Notice the link button on line no 8. I have now specify an image tag inside Link button and pass the primarykey of tbl_files as the file name along with random “.jpg”. So that, it can finally looks like as follows
The idea is, I will attach the handler with jpg file type to accommodate the incoming requests.
Now, lets create HttpHandler and name it “imageHandler”
Well, read the comments I wrote in the code. That will of course help you to understand what actually I have done.
And then register the HttpHandler.