Cannot display Word document from SQL

T

tfs

I have a word file stored in an SQL database and am trying to read and
display on my ASP.Net page. It seems to work OK as far as reading and
displaying on the page, but it is not displaying as a word document,
but as a text with all the garbage characters (formatting, non text
characters).

What am I doing wrong?

<%@ Page Language="VB"
ContentType="text/html" trace="true"
ResponseEncoding="iso-8859-1" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Temp display</title>
<script runat="server">

Sub Page_Load(sender as Object, e as EventArgs)

Dim sResults As String

Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Contour_Server")
Dim objConn as New SqlConnection (ConnectionString)
objConn.Open()

Dim CommandText as String = "select document from
openworx..qadocs"
Dim objCmd as New SqlCommand(CommandText,objConn)
Dim objCommand as SqlCommand = new SqlCommand(CommandText,
objConn)
Dim objDataReader as SqlDataReader = objCommand.ExecuteReader(
_
CommandBehavior.CloseConnection)


Dim arrByteData As Byte()

while (objDataReader.Read() = true)
if(objDataReader(0) is System.DBNull.value) then
exit while
else
Response.Clear()
Response.AddHeader("content-disposition",
"inline;filename=Stuff.doc")
Response.ContentType = "application/msword"
arrByteData =
Ctype(objDataReader(0),Byte())
response.BinaryWrite(arrByteData)
end if
end while
End Sub
</script>

</head>
<body>

</body>
</html>


Thanks,

Tom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top