Click to See Complete Forum and Search --> : Capturing ASP.Net generated HTML to a file on web server
strangedub@yaho
September 1st, 2004, 02:13 PM
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. :cool:
MRutledge
September 1st, 2004, 07:26 PM
Take a look at these 3 classes: HttpWebRequest, HttpWebResponse
and HttpWebClient. With these three classes you should be able to get a stream that is the final html. You could then write that stream to a file on the disk.
strangedub@yaho
September 2nd, 2004, 11:33 AM
Well, 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 :cool:
fongjeffrey
April 4th, 2005, 10:29 PM
Hi there,
Coincidently I am doing sth very similar to what you did. I need to save the entire .aspx/html file in the server, and display it at later time. This is my code:
string m_OutputFile = @"c:\myDir\myFile.htm";
string path = this.Server.MapPath("..\\images\\myFile.htm");
StreamWriter sw = new StreamWriter(path,true);
Server.Execute("mypage.aspx", sw);
sw.Flush();
sw.Close();
this portion of code is called whenever a "save" button is pressed. Somehow this portion of code is calling over and over?? Do you know why? and how to fix this problem?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.