|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Read Word docs from Image (BLOB) Column in SQL ServerI'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(); On Sun, 2 Jul 2006 09:12:01 -0700, excession <excess***@discussions.microsoft.com> wrote:
¤ 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(); Do you know how they were added to the database? Were they added as OLE objects? Paul ~~~~ Microsoft MVP (Visual Basic) Yes, they were added as OLE objects.
I thought that I could simply pull the objects from the database and open them without any hassle.. but I haven't had any luck yet. Show quote "Paul Clement" wrote: > On Sun, 2 Jul 2006 09:12:01 -0700, excession <excess***@discussions.microsoft.com> wrote: > > ¤ 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(); > > Do you know how they were added to the database? Were they added as OLE objects? > > > Paul > ~~~~ > Microsoft MVP (Visual Basic) > Actually, if I open one of the files in notepad and scroll through the doc I
can read some of the original text. Quite a lot of it is formattet I guess.. And quite a lot has a square char between chars in words. Show quote "excession" wrote: > Yes, they were added as OLE objects. > > I thought that I could simply pull the objects from the database and open > them without any hassle.. but I haven't had any luck yet. > > "Paul Clement" wrote: > > > On Sun, 2 Jul 2006 09:12:01 -0700, excession <excess***@discussions.microsoft.com> wrote: > > > > ¤ 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(); > > > > Do you know how they were added to the database? Were they added as OLE objects? > > > > > > Paul > > ~~~~ > > Microsoft MVP (Visual Basic) > > On Wed, 5 Jul 2006 10:07:02 -0700, excession <excess***@discussions.microsoft.com> wrote:
¤ Yes, they were added as OLE objects. ¤ ¤ I thought that I could simply pull the objects from the database and open ¤ them without any hassle.. but I haven't had any luck yet. ¤ You have to strip the OLE header information before saving to a file. You might want to see if the following helps: http://sastools.com/b2/post/79394244 Paul ~~~~ Microsoft MVP (Visual Basic) I'm afraid that didn't help.
Where does Word OLE header end? 78 didn't work.. Show quote "Paul Clement" wrote: > On Wed, 5 Jul 2006 10:07:02 -0700, excession <excess***@discussions.microsoft.com> wrote: > > ¤ Yes, they were added as OLE objects. > ¤ > ¤ I thought that I could simply pull the objects from the database and open > ¤ them without any hassle.. but I haven't had any luck yet. > ¤ > > You have to strip the OLE header information before saving to a file. You might want to see if the > following helps: > > http://sastools.com/b2/post/79394244 > > > Paul > ~~~~ > Microsoft MVP (Visual Basic) > |
|||||||||||||||||||||||