ASP.Net/Response/Response Stream
Версия от 15:30, 26 мая 2010; (обсуждение)
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>
--%>