日期:2014-05-17 浏览次数:20455 次
<%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %> <script runat="server"> protected void Button1_Click(object sender, EventArgs e) { StringWriter wr = new StringWriter(); Server.Execute(this.TextBox1.Text, wr); //你可以使用第三个参数传递页面的更多初始数据 this.Label1.Text = Server.HtmlEncode(wr.ToString()); File.WriteAllText(Server.MapPath(this.TextBox2.Text), wr.ToString()); } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>演示取得当前网站中其它网页的源代码只需要两行代码就够了</title> </head> <body> <form id="form1" runat="server" defaultbutton="Button1"> <div> 请输入本网站的页面名称:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> 请输入目标文件名称<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><hr /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>