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 6: <strong>FILESTREAM</strong> with SSIS and SSRSIn this lab, the <strong>FILESTREAM</strong> file must be opened for reading, and the disk file needs to becreated and opened for writing.<strong>The</strong> data stored in the table contains the full path and file name, for example:c:\filestream\images\abc.jpeg. We created a package variable earlier to store the locationin which the image files need to be created, so we now need to build a new path basedon the file path stored in the table and the target folder location stored in the packagevariable. Listing 6-20 shows how to do this.// Open the <strong>FILESTREAM</strong> data file for readingSqlFileStream fs = new SqlFileStream(FSPathName, FSContext,FileAccess.Read);// Open the disk file for writingstring OnlyFilename = System.IO.Path.GetFileName(FileName);FileStream localFile = new FileStream(OutputFolder + OnlyFilename,FileMode.Create, FileAccess.Write);// Note that the BinaryWriter should be initialized with the// localFile objectBinaryWriter bw = new BinaryWriter(localFile);Listing 6-20:Building a path to the target location.When you have completed the changes, execute the SSIS package and verify that the<strong>FILESTREAM</strong> data is correctly exported to the target location specified in the package.<strong>The</strong> complete listings for the C# and VB source code to export BLOB valuesfrom a <strong>FILESTREAM</strong> column into disk files in the specified location are availablein the download.259

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

Saved successfully!

Ooh no, something went wrong!