Blob reading problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'm trying to read RTF and Word files from blob columns in SQL Server, but
the files can't be opened in Word when i retreive them. They seem to contain
garbage... What am I doing wrong?

This is some of the code used to get the files:

FileStream fileStream = new FileStream(filename, FileMode.Create,
FileAccess.Write);
BinaryWriter binaryWriter = new BinaryWriter(fileStream);

long totalBytes = sqlDataReader.GetBytes(blobColumn, 0, null, 0,
int.MaxValue);

byte[] outbyte = new byte[totalBytes];
sqlDataReader.GetBytes(blobColumn, 0, outbyte, 0, (int)totalBytes);
binaryWriter.Write(outbyte, 0, (int)totalBytes);
binaryWriter.Flush();

binaryWriter.Close();
fileStream.Close();
 
Thus wrote excession,
Hi

I'm trying to read RTF and Word files from blob columns in SQL Server,
but the files can't be opened in Word when i retreive them. They seem
to contain garbage... What am I doing wrong?

This is some of the code used to get the files:

FileStream fileStream = new FileStream(filename, FileMode.Create,
FileAccess.Write);
BinaryWriter binaryWriter = new BinaryWriter(fileStream);
long totalBytes = sqlDataReader.GetBytes(blobColumn, 0, null, 0,
int.MaxValue);

byte[] outbyte = new byte[totalBytes];
sqlDataReader.GetBytes(blobColumn, 0, outbyte, 0, (int)totalBytes);
binaryWriter.Write(outbyte, 0, (int)totalBytes); binaryWriter.Flush();

binaryWriter.Close();
fileStream.Close();

Using a BinaryWriter for arbitrary binary content is a potentially destructive
operation. To copy the data "as is", write it directly to your FileStream.

Cheers,
 
Back
Top