Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2004, 08:44 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default display word document in form

Hi,

I have an application that allows the site manager to upload a word document which he wants displayed to the site users.
The upload works fine however the display doesn't work. It works for txt, images and html but not for .doc files. When I want to diplay a word document it jumps to the catch phrase.

Below is the code (text refers to the file name that is stored in the db).


    If Path.GetExtension(text) = ".doc" Or Path.GetExtension(text) = ".txt" Or Path.GetExtension(text) = ".html" Or Path.GetExtension(text) = ".htm" Then



            Dim f As Integer = FreeFile()

             Try



                  If Path.GetExtension(text) = ".doc" Or Path.GetExtension(text) = ".txt" Or Path.GetExtension(text) = ".html" Or Path.GetExtension(text) = ".htm" Then

                     FileOpen(f, Server.MapPath("../lawImages/" & text), OpenMode.Input)

                        End If



             Dim myHTML = InputString(f, LOF(f))

               FileClose(f)



               Return "<TD vAlign=""middle"" align=""center"" width=""50px"" height=""50px"">" & myHTML & ""





             Catch

             Return "<div align=center><Img src=""../images/police.jpg "" id=""img"" height=""50"" width=""50""></div>"

             End Try

       Else



            Return text

           End If






I also tried the following code but it also shows garbage of the word document:


    'Set the appropriate ContentType.

        Response.ContentType = "application/msword"

        'Get the physical path to the file.

        Dim FilePath As String = Server.MapPath("../lawImages/" & text)

        'Write the file directly to the HTTP output stream.

        Response.WriteFile(FilePath)

        Response.End()
 
Old September 12th, 2004, 09:53 PM
Registered User
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It might be easier all round if you just have a frame (or IFrame) sat next to your menu that points to the specified file. If you point a frame to a word document, Internet Explorer will open Word and display it within that frame.

<frame src="http://www.myserver.com/uploadedfiles/WordFile.doc">

If you then point this frame to a text file or HTML file, they will both be displayed properly

(this all depends on the clients computer however, they must have Word installed and have it set to open in the browser!)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Document to PDF BSkelding ASP.NET 1.0 and 1.1 Professional 2 July 19th, 2013 04:53 AM
Print Word document from Access Form ppenn Access VBA 2 December 14th, 2005 07:51 AM
Create and Save ASP form Contents to Word Document abhisheksud Classic ASP Professional 1 October 13th, 2005 04:00 AM
Checkbox on word document kareltje Excel VBA 3 February 17th, 2005 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.