How to display a word document (.doc) file in html page using ASP?

Questions by uni_enjoy   answers by uni_enjoy

Showing Answers 1 - 4 of 4 Answers

Mai Nguyen

  • Mar 22nd, 2006






  • 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

3'declare all variables
4Dim objWord
5Dim oDoc
6Dim objFso
7Dim colFiles
8Dim curFile
9Dim curFileName
10Dim folderToScanExists
11Dim folderToSaveExists
12Dim objFolderToScan
14'set some of the variables
15folderToScanExists = False
16folderToSaveExists = False
17Const wdSaveFormat = 10 'for Filtered HTML output
20'change the following to fit your system
21Const folderToScan = "C:Worddocumentation"
22Const folderToSave = "C:Inetpubwwwrootword"
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
33    MsgBox "Folder to scan from does not exist!", 48, "File System Error"
34End If
35If objFso.FolderExists(folderToSave) Then
36    folderToSaveExists = True
38    MsgBox "Folder to copy to does not exist!", 48, "File System Error"
39End If
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
78Set objFso = Nothing

  Was this answer useful?  Yes


  • May 15th, 2006

copy the .doc file to the www root folder 

example:- data.doc

and give the link in the asp page as



lastly save it as .asp file

  Was this answer useful?  Yes


  • Oct 13th, 2006

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/" %> 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

  Was this answer useful?  Yes


  • Feb 26th, 2007

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

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions