J
John
I need to store a variety of items in SQL Server. These could be text
files, pictures, word documents, PDF, etc. I have set up my database
to accept a varbinary(max) and I can put the items into the database
as follows:
Dim filename As String
OpenFileDialog1.ShowDialog()
filename = OpenFileDialog1.FileName
Dim fs As New FileStream(filename, FileMode.Open,
FileAccess.Read)
Dim ilen As Integer = CInt(fs.Length)
Dim bFile(ilen) As Byte
fs.Read(bFile, 0, ilen)
fs.Close()
I then call the code to put the item into the database using a binary
type in the System.Data.Generic namespace. The item is in the
database. In this case it was a word document.
Retreiving the document is use the following code:
For Each rw As DataRow In dt.Rows
Dim bFile() As Byte = rw.Item(1)
Dim ms As New MemoryStream(bFile)
Dim data As String = Encoding.ASCII.GetString(bFile)
Next
The string in data comes back as "??????
Does anyone have any idea or code that will convert a word doc back
from binary? Or is there a better way to store word documents in SQL
Server. Understand that we must store the documents in the database
because we have to go to one source for all the data during the
certification process so the file has to be in the database.
Thanks.
John
files, pictures, word documents, PDF, etc. I have set up my database
to accept a varbinary(max) and I can put the items into the database
as follows:
Dim filename As String
OpenFileDialog1.ShowDialog()
filename = OpenFileDialog1.FileName
Dim fs As New FileStream(filename, FileMode.Open,
FileAccess.Read)
Dim ilen As Integer = CInt(fs.Length)
Dim bFile(ilen) As Byte
fs.Read(bFile, 0, ilen)
fs.Close()
I then call the code to put the item into the database using a binary
type in the System.Data.Generic namespace. The item is in the
database. In this case it was a word document.
Retreiving the document is use the following code:
For Each rw As DataRow In dt.Rows
Dim bFile() As Byte = rw.Item(1)
Dim ms As New MemoryStream(bFile)
Dim data As String = Encoding.ASCII.GetString(bFile)
Next
The string in data comes back as "??????
Does anyone have any idea or code that will convert a word doc back
from binary? Or is there a better way to store word documents in SQL
Server. Understand that we must store the documents in the database
because we have to go to one source for all the data during the
certification process so the file has to be in the database.
Thanks.
John