Archive

Archive for April, 2005

Rendering Word documents

April 4, 2005 Leave a comment

Recently ran into a couple of issues related to rendering word documents from ASP.NET.

Set Response.ContentType to "application/word" and Add a Content-Disposition header with value "inline, filename=test.doc" or "attachment, filename=test.doc".

This should open the HTML output in word.

Two unique problems we faced in this:

1. Remove the ViewState hidden and other unwanted ASP.NET plumbing

2. Add a Page Break foricbly.

For 1 used the control’s RenderControl method from the Render method of the page after clearing all the existing content using Response.Clear

For 2 used a the following <br clear="all" style="page-break-before:always">

Thanks to google as usual.

Advertisements
Categories: ASP .NET