62,047
社区成员
发帖
与我相关
我的任务
分享
//根据URL生成静态页面
protected void tohtml(string Url,int ID)
{
Encoding code = Encoding.GetEncoding("utf-8");
//StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//读取远程路径
//WebRequest temp = WebRequest.Create(Url);
//WebResponse myTemp = temp.GetResponse();
//sr = new StreamReader(myTemp.GetResponseStream(), code);
System.Net.WebClient wc = new System.Net.WebClient();
Byte[] pageData = wc.DownloadData(Url);
str = System.Text.Encoding.UTF8.GetString(pageData);
//读取
//try
//{
// sr = new StreamReader(myTemp.GetResponseStream(), code);
// str = sr.ReadToEnd();
//}
//catch (Exception ex)
//{
// throw ex;
//}
//finally
//{
// sr.Close();
//}
string fileName = "Niche_"+ID + ".html";
//写入
try
{
sw = new StreamWriter(Server.MapPath("/html/"+MemberName+"/") + fileName, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
Response.Write("恭喜<a href=html/" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在html文件夹下!");
}
}