default.aspx页面
<div>
<asp:TextBox ID="Title" runat="server"></asp:TextBox> <asp:Button ID="Button2"
runat="server" Text="Button" οnclick="Button2_Click" />
</div>
.cs页面代码
protected void Button2_Click(object sender, EventArgs e)
{
Encoding code = Encoding.Default;
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//读取远程路径
WebRequest temp = WebRequest.Create(Title.Text.Trim());
WebResponse myTemp = temp.GetResponse();
sr = new StreamReader(myTemp.GetResponseStream(), code);
//读取
try
{
sr = new StreamReader(myTemp.GetResponseStream(), code);
str = sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr.Close();
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";
//写入
try
{
sw = new StreamWriter(Server.MapPath(fileName), false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
Response.Write("恭喜<a href=" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在根目录文件夹下!");
}
}