|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Blob reading problemsI'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,
Show quote > Hi Using a BinaryWriter for arbitrary binary content is a potentially destructive > > 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(); operation. To copy the data "as is", write it directly to your FileStream. Cheers, -- Joerg Jooss news-re***@joergjooss.de |
|||||||||||||||||||||||