Posts

Showing posts from January, 2010

Rendering ASP.NET MVC Viewer by email

Last couple of days I had a bit of a trouble. I was working for a client that wanted to automatically notify his deliveries to the company that was doing the delivery. The task was just another branch of a bigger project.
I had managed to keep the project relatively simple in my view, and I did not want to start generating PDF's and then attaching to an email. All this automatically, of course.
The client is developing all the new software in .NET so the language wasn´t a choice. I was using the MVC framework and I had already a view that was rendering exactly what they wanted to be emailed. So I thought to myself "If I could just send the rendered view...".
I did a little bit of searching on the Web and found this on StackOverflow. Using one of the answers to the question I got this code working:

Dim httpStream = New IO.MemoryStream()
Dim httpWriter = New IO.StreamWriter(httpStream, Encoding.Unicode)
Dim vp = New ViewPage()

Dim response = Sys…