Advertisement
Advertisement
| 03.25.2008 at 12:26AM PDT, ID: 23266264 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: |
const int CHUNK_SIZE = 1024 * 8; //8K write buffer.
using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
{
reader.Read();
// Get the file size by passing null as the byte array parameter.
long fileSize = reader.GetBytes(0, 0, null, 0, 0);
stBinaryFileStream.SetLength(fileSize + CHUNK_SIZE);// Set the Memory Streams internal array size in bytes to the anticipated file size + 1 chunk for luck.
long bytesRead = 0;
byte[] buffer = new byte[CHUNK_SIZE];
int read = 0;
while (bytesRead < fileSize)
{
read = (int)reader.GetBytes(0, bytesRead, buffer, 0, buffer.Length);
stBinaryFileStream.Write(buffer, 0, read);
bytesRead += read;
}
lTotalBytesRead = bytesRead;
reader.Close();// explicitly close the reader.
}
|