views:

178

answers:

2

I'm writing a WinForms application that sends email messages (like a mail merge).

I'd like to use ASP.Net's rendering engine to render the HTML bodies of the messages.

What's the simplest way to get the rendered output of a single ASPX page without the entire ASP.Net runtime?

To make things harder, I'd prefer to compile the ASPX at runtime so that it can be modified without rebuilding the application. However, this is not a requirement; if it's too difficult, I'll give up on it.

+2  A: 

Rick Strahl posted an article how to do this at this location: http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.asp. I know there is a way to call some internal .NET Framework methods but I can't remember what they are off hand.

Wil P
A: 

You may want to consider using a templating lib like NVelocity. Using the WebForms rendering engine in this manner is a bit overkill and hackish at best.

As an aside: keep in mind that HTML in email sucks. Even the most elementary of CSS is ignored by the majority of email clients. If you want my advice, KISS and save your sanity: if you're going to automate emails, send only plain text.

dustyburwell
We use ASPX for plain text emails too from ASP.NET (not from a fat client). Works pretty well and is easy to make dynamic :) One other reason to use this method is it's easy to hand the ASPX over to a designer and let them lay it out around your server controls. This way you don't have to spend your time bothering with layout, but, just making it work with the dynamic data.
Wil P