How to convert word to html with .net

D

Doug Batchelor

I store word docs in a sql2005 database as images. I can retrieve the docs
from the database as byte arrays. I need to be able to then save the docs as
temporary files on the server in html format. I think I sould be able to use
microsoft.office.interop.word to accomplish this but I have no idea how to
start. I am using asp.net 2.0 and vb.net. If anyone has any vb ( or c# code
that I could use, I would really appreciate it)
 
S

Shauna Kelly

Hi Doug

In VBA you would need something like the following. You'll need to
translate the syntax to the language your choice.

Sub SaveActiveDocAsHTML

Dim oDoc as Word.Document
Dim appWord as Word.Application
Dim sSavePFN as string

set appWord = Word.Application 'you'll have to get a reference to
the Word app some how

on error resume next
'You can't ever be certain that there is an active document
set oDoc = appWord.ActiveDocument
on error goto 0 'you need better error handling in the real world

'Get the path and file name to which you want to save the document
sSavePFN = "c:\whatever\somewhere.htm"

oDoc.SaveAs FileName:=sSavePFN , _
FileFormat:=wdFormatHTML, _
AddToRecentFiles:=True

End Sub

This will save the document as an HTML file at the location specified.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top