473,790 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot display Word document from SQL

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="te xt/html" trace="true"
ResponseEncodin g="iso-8859-1" %>
<%@ import Namespace="Syst em.Data" %>
<%@ import Namespace="Syst em.Data.SqlClie nt" %>
<html>
<head>
<title>Temp display</title>
<script runat="server">

Sub Page_Load(sende r as Object, e as EventArgs)

Dim sResults As String

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_Contour_Serv er")
Dim objConn as New SqlConnection (ConnectionStri ng)
objConn.Open()

Dim CommandText as String = "select document from
openworx..qadoc s"
Dim objCmd as New SqlCommand(Comm andText,objConn )
Dim objCommand as SqlCommand = new SqlCommand(Comm andText,
objConn)
Dim objDataReader as SqlDataReader = objCommand.Exec uteReader(
_
CommandBehavior .CloseConnectio n)
Dim arrByteData As Byte()

while (objDataReader. Read() = true)
if(objDataReade r(0) is System.DBNull.v alue) then
exit while
else
Response.Clear( )
Response.AddHea der("content-disposition",
"inline;filenam e=Stuff.doc")
Response.Conten tType = "applicatio n/msword"
arrByteData =
Ctype(objDataRe ader(0),Byte())
response.Binary Write(arrByteDa ta)
end if
end while
End Sub
</script>

</head>
<body>

</body>
</html>
Thanks,

Tom.

Nov 18 '05 #1
1 1552
This article provides a working example for you:
http://searchvb.techtarget.com/vsnet...293033,00.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"tfs" <tf*@dslextre me-dot-com.no-spam.invalid> wrote in message
news:40******** **@Usenet.com.. .
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="te xt/html" trace="true"
ResponseEncodin g="iso-8859-1" %>
<%@ import Namespace="Syst em.Data" %>
<%@ import Namespace="Syst em.Data.SqlClie nt" %>
<html>
<head>
<title>Temp display</title>
<script runat="server">

Sub Page_Load(sende r as Object, e as EventArgs)

Dim sResults As String

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI N
G_Contour_Serve r") Dim objConn as New SqlConnection (ConnectionStri ng)
objConn.Open()

Dim CommandText as String = "select document from
openworx..qadoc s"
Dim objCmd as New SqlCommand(Comm andText,objConn )
Dim objCommand as SqlCommand = new SqlCommand(Comm andText,
objConn)
Dim objDataReader as SqlDataReader = objCommand.Exec uteReader(
_
CommandBehavior .CloseConnectio n)
Dim arrByteData As Byte()

while (objDataReader. Read() = true)
if(objDataReade r(0) is System.DBNull.v alue) then
exit while
else
Response.Clear( )
Response.AddHea der("content-disposition",
"inline;filenam e=Stuff.doc")
Response.Conten tType = "applicatio n/msword"
arrByteData =
Ctype(objDataRe ader(0),Byte())
response.Binary Write(arrByteDa ta)
end if
end while
End Sub
</script>

</head>
<body>

</body>
</html>
Thanks,

Tom.

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
6933
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
8
5483
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
1
2412
by: vikram | last post by:
hello all, I have a small question. I have an application which actually converts binary data to word document and saves on the server. The next phase of the project involves opening the word document which I created. But i get the following error when i tried to open the word document. "Internet Explorer cannot download file.doc from virtualdirectoryname.com Internet Explorer was not able to open this Internet site. The requested
0
1372
by: bottas | last post by:
A VB module uses the Word object model. Late bound objects. I'm searching for hidden text. At a certain point, my code simply hangs. I have error trapping in place, but no exceptions occur. But if I pause the program and try to evaluate my range object (rng), to see what's up, I get a message "Expression cannot be evaluated at this time." in the immediate window. With minor differences, the code I'm using is pasted from a working VB6...
2
3186
by: =?Utf-8?B?c2NvdHRybQ==?= | last post by:
Hi I am using a SQL Server 2005 varbinary(max) to store word documents in the database. I can retrive the data out into a MemoryStream object ok but I want to be able to use this to display the file in a web browser from an asp.net page. I found quite a lot of articles like this http://support.microsoft.com/kb/306654 that tell you do do it from a file on a hard disk but not directly from a stream object, any ideas. I would rather not...
7
3612
exoskeleton
by: exoskeleton | last post by:
hi guys..hope you can help me...my boss want me to edit our website and apply the tooltip thing, i mean the moving tooltip that follows the mouse.. please help...thank you... :(
4
8284
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
12
2494
by: GuangXiN | last post by:
I want the file upload element disappear, instead of it, I place a text box and a button with my own css defination. but it doesn't work on IE7. What should I do now? <form action="upload.php" method="POST" enctype="multipart/form-data"> <p> <span>Select photo:</span> <input type="file" name="photo" style="display:none;"> <input type="text" name="photoUrl" class="s1" /> <input type="button" class="s2"...
3
4559
by: Mufasa | last post by:
I need to write a windows program in C# that will display a word document on the screen without having Word loaded on the machine. How can I do this? TIA - J.
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.