Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How save a In-mory ASP.NET page to disk???
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00769883
Message ID:
00771603
Views:
9
Just as an aside to anyone who's listening, here's how you do this if you want to capture the output and then still display the ASP.Net page which requires writer.Write() with the generated string.

In my scenario I need to display the result page and use a portion of it for my Email confirmation, so I simply capture the content strip out some stuff then send it:
protected override void Render (HtmlTextWriter writer) 
{
	// *** Write the HTML into this string builder
	StringBuilder sb = new StringBuilder();
	HtmlTextWriter hWriter = new HtmlTextWriter(new StringWriter(sb));
	base.Render(hWriter);

	// *** store to a string
	string PageResult = sb.ToString(); 

	// *** Write it back to the server
	writer.Write(PageResult);

	// *** Now strip out confirmation part
	string Confirmation = wwUtils.StrExtract(PageResult,"<!--  Start Confirmation Display --->",
		"<!-- End Confirmation Display --->");

	if (wwUtils.Empty(Confirmation)) 
		return;

	// *** Turn this text into an HTML document and add 
	// *** headers and style sheet
	Confirmation = Confirmation.Replace("Your Order Confirmation","West Wind Technologies Order Confirmation");

	// *** TODO: Add Style Sheet
	sb = new StringBuilder();
	sb.Append("<html><body>");
	sb.Append(Confirmation);
	sb.Append(" </body></html>");


	this.SendConfirmationEmail(sb.ToString());
}
This is definitely cool though - because I have a number of pages where part of the page gets generated needs to be reused for multiple purposes. Doing this any other way would be way more complicated since .Net doesn't easily support some sort of mail merge (well it does by using the ASP.Net runtime which would incur a fair amount of overhead).

Thanks. Certainly saved me some time (those damn Writers <g>)...

+++ Rick ---


>Rick,
>
>Here is how to get the HTML generated before it is sent to the client:
>
>
>protected override void Render (HtmlTextWriter writer)
>{
>	StringBuilder stringBuilder = new StringBuilder();
>	StringWriter stringWriter = new StringWriter(stringBuilder);
>	HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
>	base.Render(htmlWriter);
>	string yourHtml = stringBuilder.ToString();
>	// yourHtml string contains the HTML generated
>}
>
>
>>ACtually I need to something like this as well - I need to actually use content generated from an ASP page in an email confirmation and I want to capture the output generated before it gets sent back to the client.
>>
>>I suspect there are events on teh HTTPRuntime to do this but I haven't gotten this far yet...
>>
>>+++ Rick ---
>>
>>
>>>Mario,
>>>
>>>How about caching the page? It would be faster than writing to disk. Here is an article that explains how to setup your page to use caching:
>>>
>>>http://www.sitepoint.com/article/1007
>>>
>>>
>>>>I build a complete ASP.NET page in run-time. That it, i add the controls, validators, and do a manual bind of the data. I need that because the layaout and controls can change, but that not happend so much.
>>>>
>>>>This meaning that the system rebuild in each hit the whole page. So i like to store the page in disk the first time and get them from here, and rebuild only when the layout&control change, and only set the data from my database.
>>>>
>>>>How i can do that????
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Reply
Map
View

Click here to load this message in the networking platform