Compile ASPX in WinForms App
Asked Answered
B

2

4

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.

Benignity answered 29/10, 2009 at 2:28 Comment(3)
This is not an exact duplicate; the other questions are either serving arbitrary pages over HTTP or running within ASP .Net.Benignity
by rendering you mean as user types email you give html preview of it?Littlefield
No; I mean rendering an ASPX with embedded code to a string I can send by email. I don't need to actually render the HTML onscreen.Benignity
T
4

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.

Treachery answered 29/10, 2009 at 4:5 Comment(0)
F
0

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.

Fiche answered 29/10, 2009 at 4:18 Comment(1)
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.Treachery

© 2022 - 2024 — McMap. All rights reserved.