GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  ASP
Go To First  |  Previous Question  |  Next Question 
 ASP  |  Question 128 of 147    Print  
How to display a word document (.doc) file in html page using ASP?

  
Total Answers and Comments: 4 Last Update: February 26, 2007     Asked by: uni_enjoy 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 22, 2006 21:09:06   #1  
Mai Nguyen        

RE: How to display a word document (.doc) file in html...

  • They are already familiar with Word and its formatting features.
  • Word comes installed on their computer and they do not want to purchase additional HTML authoring software.
  • They have numerous files in Word format that they want on a website in HTML. Simply exporting them to HTML is the fastest way.

Save AS HTML from wordwith the extension .htmand exporting via code using vbscript

Option Explicit

2
3'declare all variables
4Dim objWord
5Dim oDoc
6Dim objFso
7Dim colFiles
8Dim curFile
9Dim curFileName
10Dim folderToScanExists
11Dim folderToSaveExists
12Dim objFolderToScan
13
14'set some of the variables
15folderToScanExists False
16folderToSaveExists False
17Const wdSaveFormat 10 'for Filtered HTML output
18
19'********************************************
20'change the following to fit your system
21Const folderToScan C:\Word\documentation\
22Const folderToSave C:\Inetpub\wwwroot\word\
23'********************************************
24
25'Use FSO to see if the folders to read from
26'and write to both exist.
27'If they do then set both flags to TRUE
28'and proceed with the function
29Set objFso CreateObject( Scripting.FileSystemObject )
30If objFso.FolderExists(folderToScan) Then
31 folderToScanExists True
32Else
33 MsgBox Folder to scan from does not exist! 48 File System Error
34End If
35If objFso.FolderExists(folderToSave) Then
36 folderToSaveExists True
37Else
38 MsgBox Folder to copy to does not exist! 48 File System Error
39End If
40
41If (folderToScanExists And folderToSaveExists) Then
42 'get your folder to scan
43 Set objFolderToScan objFso.GetFolder(folderToScan)
44 'put al the files under it in a collection
45 Set colFiles objFolderToScan.Files
46 'create an instance of Word
47 Set objWord CreateObject( Word.Application )
48 If objWord Is Nothing Then
49 MsgBox Couldn't start Word. 48 Application Start Error
50 Else
51 'for each file
52 For Each curFile in colFiles
53 'only if the file is of type DOC
54 If (objFso.GetExtensionName(curFile) doc ) Then
55 'get the filename without extension
56 curFileName curFile.Name
57 curFileName Mid(curFileName 1 InStrRev(curFileName . ) - 1)
58 'open the file inside Word
59 objWord.Documents.Open objFso.GetAbsolutePathName(curFile)
60 'do all this in the background
61 objWord.Visible False
62 'create a new document and save it as Filtered HTML
63 Set oDoc objWord.ActiveDocument
64 oDoc.SaveAs folderToSave & curFileName & .htm wdSaveFormat
65 oDoc.Close
66 Set oDoc Nothing
67 End If
68 Next
69 End If
70 'close Word
71 objWord.Quit
72 'set all objects and collections to nothing
73 Set objWord Nothing
74 Set colFiles Nothing
75 Set objFolderToScan Nothing
76End If
77
78Set objFso Nothing

 
Is this answer useful? Yes | No
May 15, 2006 07:27:10   #2  
hema        

RE: How to display a word document (.doc) file in html...

copy the .doc file to the www root folder

example:- data.doc

and give the link in the asp page as

<html>

<head>

<title></title>

</head>

<body>

<a href data.doc >Document</a>

</body>

</html>

lastly save it as .asp file


 
Is this answer useful? Yes | No
October 13, 2006 07:07:26   #3  
nagendra        

RE: How to display a word document (.doc) file in html...
There is a way to direct the html produced from an ASP page to Word document instead of displaying it in standard browser and in order to do that you have to change the content type of the server response. Put the following line on the top of your ASP page: < Response.ContentType application/vnd.ms-word > When you access this ASP page from your browser a Word document will be opened inside of the browser and all the content generated by the ASP page will appear in this document....n
 
Is this answer useful? Yes | No
February 26, 2007 06:53:24   #4  
shweta        

RE: How to display a word document (.doc) file in html...

One can access word or any file uisng File System Object as:

dim fso
dim wordfile

set fso Server.createObject("Scripting.FileSystemObject")

wordfile fso.opentextfile(path).readall

set fso nothing


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape