/// <summary>
/// 创建静态页
/// </summary>
/// <param name="MuBanPath">模板页路径(物理路径)</param>
/// <param name="HtmlHomePath">静态页面保存的文件夹路径(一般为虚拟路径,例:"~/htmls/")</param>
/// <param name="HtmlName">htmlName(一般格式:xinxi_id.htm,页面只有一个,则xinxi.htm)</param>
/// <returns></returns>
public static bool Create(string MuBanPath, string HtmlHomePath, string HtmlName)
{
bool state = true;//返回标识
string path = HttpContext.Current.Server.MapPath(HtmlHomePath) + HtmlName;//找到文件夹的物理路径得到保存全路径
System.Text.Encoding code = System.Text.Encoding.GetEncoding("utf-8");//创建一种编码
System.IO.StreamReader sr = null;
System.IO.StreamWriter sw = null;
System.Text.StringBuilder str = new System.Text.StringBuilder();
System.Net.WebRequest temp = System.Net.WebRequest.Create(MuBanPath); //远程读取模板页路径
System.Net.WebResponse mytemp = temp.GetResponse();
sr = new System.IO.StreamReader(mytemp.GetResponseStream, code);//读取模板页信息
try
{
try
{
sr = new System.IO.StreamReader(mytemp.GetResponseStream, code);
str.Append(sr.ReadToEnd());//读取
}
catch (Exception)
{
state = false;
}
finally
{
sr.Close();
}
sw = new System.IO.StreamWriter(path, false, code);
sw.Write(str.ToString());//写入
sw.Flush();
}
catch (Exception ex)
{
state = false;
}
finally
{
sw.Close();
}
return state;
}