1. 程式人生 > >discuz將動態頁轉換為靜態html

discuz將動態頁轉換為靜態html

----呼叫方法 

for (int i = 0; i < 10; i++)
        {
            transHtml("../software/addsoft.aspx?type=1&id=" + i, i + "sdsdsdsds.html");
        } 

/// <summary>
  /// 轉換為靜態html
  /// </summary>
  public void transHtml(string path,string outpath)       
  {
   Page page = new Page();
   StringWriter writer = new StringWriter();
   page.Server.Execute(path, writer);
   FileStream fs;
   if(File.Exists(page.Server.MapPath("") + "//" + outpath))             
   {
    File.Delete(page.Server.MapPath("") + "//" + outpath);
    fs = File.Create(page.Server.MapPath("") + "//" + outpath);
   }
   else           
   {
    fs = File.Create(page.Server.MapPath("") + "//" + outpath);
   }
   byte[] bt = Encoding.Default.GetBytes(writer.ToString());
   fs.Write(bt,0,bt.Length);
   fs.Close();
  }