Mikelon85
Mikelon85

Reputation: 432

How can I save asp generated page in html archive?

I want to save the result of processing an ASP page as html file. Anyone knows if is that possible? Thanks

Upvotes: 1

Views: 1471

Answers (1)

Rahat Khanna
Rahat Khanna

Reputation: 4672

This can help you save the output of the ASP Page

<script runat="server">
void Page_Load() {
  String inputFile = MapPath("input-page.aspx");
  String sDiskFile = "result.htm";

  WebRequest webRequest = WebRequest.Create(inputFile);

  WebResponse webResponse = webRequest.GetResponse();
  Stream stream = webResponse.GetResponseStream();

  StreamReader oReader = new StreamReader(stream, Encoding.ASCII);

  StreamWriter oWriter = new StreamWriter(Server.MapPath(sDiskFile));
  oWriter.Write(oReader.ReadToEnd());

  oWriter.Close();
  oReader.Close();
  webResponse.Close();

  // display confirmation that it worked
  lblOutput.Text = inputFile;
  aLink.Text = sDiskFile;
  aLink.NavigateUrl = sDiskFile;

}
//-----------------------------------------
</script>

Upvotes: 1

Related Questions