How do I link to a word document?

liunx

Guest
Is it possible to have a button on a web form which links to a word document?

Also, is it possible to link an aspx page to a word document so that if the text on the aspx page is updated (the text comes from the database), the word document is also updated???

Thanks for any comments/ suggestions :)Ok worked out the first part, but the second???

CheersYeah, it seems possible. There isn't a web control or anything in the .Net framework designed to do specifically what you want though, you'd have to design it. If it were me then I would simply store the text into the database per the usual methods, and then I would either recreate the word document or modify it.

The two methods I have used to modify office documents is with COM objects and with XML. COM objects are pretty easy to use but I have run into trouble with them. One problem is that if you do not handle COM references correctly then the Office application will not properly shutdown when you call the quit() method and the second problem is that using COM objects requires higher privileges than the ASPNET account is granted. Using impersonation solves the problem, however impersonation may create new problems for you.

You can also use XML/XSL to create an XML Word document (WordML) for Word 2000 and newer. This is very easy and very quick. Hope that helps.Hi, thanks loads for the help. Can I ask how it all works? So would I write the document in xml and use xsl to transform this into a word document?

Thanks loadsYes, that's exactly how you'd do it. The easiest way I would think is to put the data into a dataset and create a new xmldatadocument with that dataset, then create a new xsl.xsltransform and perform the transformation.

Here's a quick (untested) example of how to do the transformation:

'### DsData is a dataset with your data in it and xslPath is a string with the path to your xsl file ###

Dim Strm As New System.IO.MemoryStream
Dim xmlWriter As New System.Xml.XmlTextWriter(Strm, Nothing)

Dim xmlData As New System.Xml.XmlDataDocument(DsData)
xmlData.WriteStartDocument()

Dim xslTrans As New System.Xsl.XslTransform
xslTrans.Load(xslPath)
xslTrans.Transform(xmlData,Nothing,xmlWriter,Nothing)

Response.ClearContent()
Response.ClearHeaders()
Response.AddHeader("content-disposition","attachment; filename=document.doc")
Response.BinaryWrite(Strm.ToArray())
Response.Flush()

Strm.Close()Cool thanks I will have to do some research into it first but you've been a really great help!!!

Thanks
 
Back
Top