J
Jeppe Dige Jespersen
I am building a page that takes a single parameter: documentId. I have
documents stored in a SQL Server 2005 database. Storing and retrieving these
from a WinForms application works fine. No problemo there.
But, when retrieving the docs from my asp.net page, the docs are somehow
corrupted, and I cannot open them using MS Word.
Documents are stored in the "data" field of my Documents table. The "data"
fields is of datatype Image. The documentId parameter is used to select the
right document from the table.
Any ideas? Anything, anyone? Any help appreciated....
/j.jespersen
***************
<%@ Page Language="VB" %>
<script runat="server">
Public Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim con As New
System.Data.SqlClient.SqlConnection("server=myServer;database=myDatabase;integrated
security=true")
Dim cmd As New System.Data.SqlClient.SqlCommand("Select * From
Documents where id=" & Request.QueryString("documentId"), con)
con.Open()
Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
If dr.Read Then
Response.Clear()
Response.AddHeader("Content-Type", "application/msword")
Response.AddHeader("Content-disposition", "attachment;
filename=myword.docx")
Response.BinaryWrite(CType(dr("data"), Byte()))
End If
con.Close()
con = Nothing
End Sub
</script>
***************
documents stored in a SQL Server 2005 database. Storing and retrieving these
from a WinForms application works fine. No problemo there.
But, when retrieving the docs from my asp.net page, the docs are somehow
corrupted, and I cannot open them using MS Word.
Documents are stored in the "data" field of my Documents table. The "data"
fields is of datatype Image. The documentId parameter is used to select the
right document from the table.
Any ideas? Anything, anyone? Any help appreciated....
/j.jespersen
***************
<%@ Page Language="VB" %>
<script runat="server">
Public Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim con As New
System.Data.SqlClient.SqlConnection("server=myServer;database=myDatabase;integrated
security=true")
Dim cmd As New System.Data.SqlClient.SqlCommand("Select * From
Documents where id=" & Request.QueryString("documentId"), con)
con.Open()
Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
If dr.Read Then
Response.Clear()
Response.AddHeader("Content-Type", "application/msword")
Response.AddHeader("Content-disposition", "attachment;
filename=myword.docx")
Response.BinaryWrite(CType(dr("data"), Byte()))
End If
con.Close()
con = Nothing
End Sub
</script>
***************