/// <summary>
/// 以ASPX生成静态页
/// </summary>
/// <param name="path"></param>
/// <param name="outpath"></param>
public static void CreateHtml(string path, string outpath)
{
Page page = new Page();
string filedir = page.Server.MapPath("~/") + "\\";
if (!Directory.Exists(filedir))//如果文件夹不存在则先创建一个空的
{
Directory.CreateDirectory(filedir);
}
outpath = filedir + outpath;
if (!File.Exists(outpath))//如果文件不存在则先创建一个空的
{
//创建文件信息对象
FileInfo finfo = new FileInfo(outpath);
//以打开或者写入的形式创建文件流
using (FileStream fs = finfo.OpenWrite())
{
StringBuilder strhtml = new StringBuilder();
strhtml.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
strhtml.Append("</html>");
//根据上面创建的文件流创建写数据流
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
//把新的内容写到创建的HTML页面中
sw.WriteLine(strhtml);
sw.Flush();
sw.Close();
}
}
StreamWriter mWriter = new StreamWriter(outpath, false, System.Text.Encoding.UTF8);
StringWriter gWriter = new StringWriter();
page.Server.Execute(path, gWriter);
string str = System.Text.Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(gWriter.ToString()));
mWriter.WriteLine(str);
mWriter.Flush();
mWriter.Close();
}