By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

Capturing ASP.Net generated HTML to a file on web server

P: n/a
I am looking for a way to capture the HTML file generated by an
ASP.Net application (just as is sent back to the client) and save it
to a designated spot on the web server. Here's a bit of background:
our application has a Report function that dynamically creates a new
page containing various tables of real-time data (through the C# code
"behind" the .aspx file). We have a new requirement to add a file
save function to this report page. So, I'd like to capture the final
HTML within the the.aspx file (exactly as is sent to the browser) and
save it (with an .htm extension) on the web server. Think of it as
having the ability to do a "view source" of the final HTML, and then
saving the source back to a file on the web server. Does anyone know
of supported way to capture the generated HTML and save it
server-side? All suggestions welcome and much appreciated.

Michael Rose
Unisys Corp.
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

All you have to do is using a WebRequest instance to request that very same
page and later save the stream.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dr. StrangeDub" <st********@yahoo.com> wrote in message
news:fb********************************@4ax.com...
I am looking for a way to capture the HTML file generated by an
ASP.Net application (just as is sent back to the client) and save it
to a designated spot on the web server. Here's a bit of background:
our application has a Report function that dynamically creates a new
page containing various tables of real-time data (through the C# code
"behind" the .aspx file). We have a new requirement to add a file
save function to this report page. So, I'd like to capture the final
HTML within the the.aspx file (exactly as is sent to the browser) and
save it (with an .htm extension) on the web server. Think of it as
having the ability to do a "view source" of the final HTML, and then
saving the source back to a file on the web server. Does anyone know
of supported way to capture the generated HTML and save it
server-side? All suggestions welcome and much appreciated.

Michael Rose
Unisys Corp.

Jul 21 '05 #2

P: n/a
Hi Michael:

I'm not sure if you want to save the HTML from inside the ASP.NET
process or request the HTML from the web server inside a windows form.

Inside ASP.NET you can Server.Execute a page to get the HTML. From a
WinForm app you can use WebClient or WebRequest.

I have some code here:
http://odetocode.com/Articles/162.aspx

HTH,

--
Scott
http://www.OdeToCode.com

On Wed, 01 Sep 2004 12:57:42 -0500, Dr. StrangeDub
<st********@yahoo.com> wrote:
I am looking for a way to capture the HTML file generated by an
ASP.Net application (just as is sent back to the client) and save it
to a designated spot on the web server. Here's a bit of background:
our application has a Report function that dynamically creates a new
page containing various tables of real-time data (through the C# code
"behind" the .aspx file). We have a new requirement to add a file
save function to this report page. So, I'd like to capture the final
HTML within the the.aspx file (exactly as is sent to the browser) and
save it (with an .htm extension) on the web server. Think of it as
having the ability to do a "view source" of the final HTML, and then
saving the source back to a file on the web server. Does anyone know
of supported way to capture the generated HTML and save it
server-side? All suggestions welcome and much appreciated.

Michael Rose
Unisys Corp.


Jul 21 '05 #3

P: n/a
The Render* methods of the
System.Web.UI.HtmlControls.HtmlControl/System.Web.UI.WebControls.WebControl
may be called manually to stream the HTML to a TextWriter.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Dr. StrangeDub" <st********@yahoo.com> wrote in message
news:fb********************************@4ax.com...
I am looking for a way to capture the HTML file generated by an
ASP.Net application (just as is sent back to the client) and save it
to a designated spot on the web server. Here's a bit of background:
our application has a Report function that dynamically creates a new
page containing various tables of real-time data (through the C# code
"behind" the .aspx file). We have a new requirement to add a file
save function to this report page. So, I'd like to capture the final
HTML within the the.aspx file (exactly as is sent to the browser) and
save it (with an .htm extension) on the web server. Think of it as
having the ability to do a "view source" of the final HTML, and then
saving the source back to a file on the web server. Does anyone know
of supported way to capture the generated HTML and save it
server-side? All suggestions welcome and much appreciated.

Michael Rose
Unisys Corp.

Jul 21 '05 #4

P: n/a
Thanks to Scott, Ignacio, and Dennis for their replies. I pretty much
went with Scott's suggested use of Server.Execute. This turned out to
be quite easy. I haven't tweaked the code yet, but these five lines of
code esssentially did the job:

m_OutputFile = "c:\myDir\myFile.htm";
StreamWriter sw = new StreamWriter(m_OutputFile,true);
Server.Execute("ReportWindow.aspx", sw);
sw.Flush();
sw.Close();

Michael Rose
================
On Wed, 01 Sep 2004 12:57:42 -0500, Dr. StrangeDub
<st********@yahoo.com> wrote:
I am looking for a way to capture the HTML file generated by an
ASP.Net application (just as is sent back to the client) and save it
to a designated spot on the web server. Here's a bit of background:
our application has a Report function that dynamically creates a new
page containing various tables of real-time data (through the C# code
"behind" the .aspx file). We have a new requirement to add a file
save function to this report page. So, I'd like to capture the final
HTML within the the.aspx file (exactly as is sent to the browser) and
save it (with an .htm extension) on the web server. Think of it as
having the ability to do a "view source" of the final HTML, and then
saving the source back to a file on the web server. Does anyone know
of supported way to capture the generated HTML and save it
server-side? All suggestions welcome and much appreciated.

Michael Rose
Unisys Corp.


Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.