public class createDetailHtml
{
private string strType;
public string _strType
{
set{strType=value;}
}
public createDetailHtml()
{
strType=Date.now.year.ToString()+Date.now.month.ToString();
}
public bool getFile(string url, string strType, string pageName)
{
WebClient wc = new WebClient();
wc.Encoding = System.Text.Encoding.GetEncoding("gb2312");
byte[] buffer = null;
StreamWriter sw = null;
try
{
buffer = wc.DownloadData(url);
sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/" + strType + "/" + pageName), false, System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(System.Text.Encoding.GetEncoding("gb2312").GetString(buffer));
sw.Flush();
sw.Close();
return true;
}
catch (Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex);
System.Web.HttpContext.Current.Response.Write("<font color=red>生成失败,请重新生成!!</font>");
return false;
}
finally
{
wc.Dispose();
}
}
}
这个类我一般用在生成单个静态页面,比如添加一个编文章,马上生成,比较方便
水平有限,有误请留言