Материал из .Net Framework эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Save Response stream to a htm file (C#)
<%@Page Language="C#" %>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Net" %>
<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>
<html>
<body>
<font face="Arial,sans-serif" size="2"><b>
Used the file:
<asp:Label id="lblOutput" runat="server" />
<br />to generate the file:
<asp:Hyperlink id="aLink" runat="server" />
</b></font>
</body>
</html>
<%-- input-page.aspx
<%@Page Language="C#" %>
<%@Import Namespace="System.Drawing" %>
<script runat="server">
void Page_Load() {
lblOutput.Text = "Page generated: " + DateTime.Now.ToString();
}
</script>
<html>
<body>
<font face="Arial,sans-serif" size="2"><b>
<asp:Label id="lblOutput" runat="server" />
</b></font>
</body>
</html>
--%>