方式一:利用现有的静态模板进行内容替换生成 先定义一个静态模板template.htm,对于需要替换的内容做一个标记用于在后来进行替换 public void ToHtmByTemplate() { //定义编码方式 System.Text.Encoding code=System.Text.Encoding.GetEncoding("gb2312"); String strHtml; System.IO.StreamReader sr=new StreamReader(Server.MapPath("template.htm"),code); //读取模板并并赋值给字符串 try { strHtml=sr.ReadToEnd(); } catch(Exception ex) { throw ex; } finally { sr.Close(); } //进行内容的替换strHtml.Replace() //定义一个StreamWriter将刚读取的内容写入一个新的文件 StreamWriter sw=new StreamWriter(Server.MapPath("new_test.htm"),code); try { sw.Write(strHtml); sw.Flush(); } catch(Exception ex) { throw ex; } finally { sw.Close(); } } 方式二:利用提供的uri生成静态页面 public void ToHtmlByUri(String uri) { //定义编码方式 System.Text.Encoding code=System.Text.Encoding.GetEncoding("gb2312"); String strHtml; StreamReader sr; //根据给定uri读取内容到流 System.Net.WebRequest request=System.Net.WebRequest.Create(new Uri(uri)); System.Net.WebResponse response=request.GetResponse(); sr=new StreamReader(response.GetResponseStream(),code); //从流中读取内容并赋给字符串 try { strHtml=sr.ReadToEnd(); } catch(Exception ex) { throw ex; } finally { sr.Close(); } //写入并生成静态页面 StreamWriter sw=new StreamWriter(Server.MapPath("new_test.aspx"),false,code); try { sw.Write(strHtml); sw.Flush(); } catch(Exception ex) { throw ex; } finally { sw.Close(); } }