Rich Text Format & ASP.NET

Today I learned how to use the Response.ContentType property to cause the browser to open an ASP.NET page as a Word document in the Rich Text Format. I know how to do this in ASP to cause an Excel spreadsheet to a open in the browser. That has been one of my best technical tricks to impress a client. Now I know how to do it in ASP.NET.

I can also add a line to the header so the RTF document will open as a file attachment. I’m using this technique in a few projects that require Word documents to be created with data from the database. I would usually do this using Word documents in HTML format but the Rich Text Format allows me to open a template file which is easier to update. My code reads the template document, replaces a few fields with database values, and then delivers a finished RTF document. The formatting of the template document can be easily changed without rewriting the code.

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit exceeded. Please complete the captcha once again.