17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: <strong>FILESTREAM</strong> with ASP.NET and SilverlightCREATE PROCEDURE GetItemImageInfo(@ItemNumber VARCHAR(20))ASBEGINSELECT ItemImage.PathName() AS filePath ,GET_<strong>FILESTREAM</strong>_TRANSACTION_CONTEXT() AS txContextFROM ItemsWHERE ItemNumber = @ItemNumberENDListing 5-9:Creating the stored procedure.Creating the web page to serve images<strong>The</strong> next step is to create a web page that can serve images to the client browsers. Add anew ASP.NET web form to the project and name it GetItemImage.aspx.<strong>The</strong> design part <strong>of</strong> this page does not need any changes because this page is not used asa UI element; its purpose is only to serve the image <strong>of</strong> the specified item to the clientbrowser. In most cases, we'd use a generic handler (.ashx file) for this type <strong>of</strong> scenario,which will be slightly faster than using an ASPX page. However, we will use an ASPX pagefor simplicity.Let's start writing the code for this page. We'll begin by adding the necessary importstatements to the code file GetItemImage.aspx.cs.using System.IO;using System.Data.SqlClient;using System.Data;using System.Data.SqlTypes;Listing 5-10:<strong>The</strong> import statements.190

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!