tags:

views:

14

answers:

1

I would like to add a button on top of a webpage, which when clicked should copy the entire webpage to an MS Word document. This has to be done in ASP.

A: 

Hi Deepa!

1) First create a .doc file on the server. Then create a file system object and use it to open the .doc file and write into it:

Set file = CreateObject("Scripting.FileSystemObject")
Set wordFile = file.CreateTextFile(pathToYourDocFile, true)
wordFile.WriteLine(htmlOutput)
wordFile.close

"htmlOutput" must contain the page you want to export to word.

2) Another option is to directly work with an instance of Word as mentioned on MSDN:

Set wordApp = GetObject(, "Word.Application")
wordApp.Visible = False
wordApp.Documents.Open pathToYourDocFile
Set wordApp = Nothing

You will need to dig through the Word API in order to write content to the document.

3) Change the content tye of your page will automatically opens it in Word (if installed on the client):

Response.ContentType = "application/msword"
jdecuyper