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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: <strong>FILESTREAM</strong> with ASP.NET and Silverlight{txContext = (reader["txContext"] as byte[]);filePath = reader["filePath"].ToString();}reader.Close();//Open the <strong>FILESTREAM</strong> data file for readingSqlFileStream fs = new SqlFileStream(filePath, txContext,FileAccess.Read);//Start transferring data into filestream data fileResponse.BufferOutput = false;Response.ContentType = "video/x-ms-wmv";BinaryWriter bw = new BinaryWriter(Response.OutputStream);const int bufferSize = 4096;byte[] buffer = new byte[bufferSize];int byteCount = fs.Read(buffer, 0, bufferSize);while ( byteCount == bufferSize ){bw.Write(buffer, 0, bytes);byteCount = fs.Read(buffer, 0, bufferSize);}}//Close the filesResponse.End();bw.Close();fs.Close();}catch(Exception ex){//Do some error handling}finally{// Commit the transaction and close connectioncmd.Transaction.Commit();cn.Close();}Listing 5-24:Code that serves video files stored in a <strong>FILESTREAM</strong> database.221

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

Saved successfully!

Ooh no, something went wrong!