29 January 2009

Render aspx page to a HTML string

To render a aspx page to a HTML simply execute the following code:

   1: StringWriter writer = new StringWriter();
   2: HttpContext.Current.Server.Execute("~/MyPage.aspx", writer);

To convert to a string:



   1: writer.ToString()
 

2 comments:

Dragonfly said...

Hi,

When running this piece of code it enters a infinite loop...

Thanks

Rui said...

Hi,
The solution uses the .net framework object model.
I use this solution without any problem.
Can you post your code?