S
Simon
I'm simplying trying to download and and open word documents that are stored
in the database. I figured out how to uploaded the documents as Byte, but I
can't figure out how to get them back out properly. The following code is
what I've tried (vb.NET)... It goes as far as asking me to Save/Open the
file, but when I do, the contents of the documents is the webage that the
download link was on! I'm fairly new to programming/web development, so i'm
not totally sure what i'm doing. I hope i've included enough information.
Thanks in advance!
Simon
--- VB.NET code ---
Public Sub DownloadFile(ByVal File_Id As Integer)
Dim dr As SqlDataReader
Try
Me.OpenConnection(ConfigurationSettings.AppSettings("MD_Runs_Connection_String"))
Dim sqlCmd As New SqlCommand("usp_files_s_by_file_id", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add(New SqlParameter("@file_id", File_Id))
dr = sqlCmd.ExecuteReader()
Do While dr.Read
Dim file() As Byte = CType(dr.Item("fileData"), Byte())
memStream.Write(file, 0, file.Length)
Loop
memStream.Flush()
ContentType = dr.Item("Application/octet-stream")
Catch
Throw
Finally
dr.Close()
Me.CloseConnection()
End Try
End Sub
in the database. I figured out how to uploaded the documents as Byte, but I
can't figure out how to get them back out properly. The following code is
what I've tried (vb.NET)... It goes as far as asking me to Save/Open the
file, but when I do, the contents of the documents is the webage that the
download link was on! I'm fairly new to programming/web development, so i'm
not totally sure what i'm doing. I hope i've included enough information.
Thanks in advance!
Simon
--- VB.NET code ---
Public Sub DownloadFile(ByVal File_Id As Integer)
Dim dr As SqlDataReader
Try
Me.OpenConnection(ConfigurationSettings.AppSettings("MD_Runs_Connection_String"))
Dim sqlCmd As New SqlCommand("usp_files_s_by_file_id", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add(New SqlParameter("@file_id", File_Id))
dr = sqlCmd.ExecuteReader()
Do While dr.Read
Dim file() As Byte = CType(dr.Item("fileData"), Byte())
memStream.Write(file, 0, file.Length)
Loop
memStream.Flush()
ContentType = dr.Item("Application/octet-stream")
Catch
Throw
Finally
dr.Close()
Me.CloseConnection()
End Try
End Sub