国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net生成靜態頁

2024-07-10 13:04:31
字體:
來源:轉載
供稿:網友
國內最大的酷站演示中心!
//生成html頁
  public static bool writefile(string strtext,string strcontent,string strauthor) 
  {
   string path = httpcontext.current.server.mappath("/news/");
   encoding code = encoding.getencoding("gb2312");
   // 讀取模板文件
   string temp = httpcontext.current.server.mappath("/news/text.html");
   streamreader sr=null;
   streamwriter sw=null;
   string str="";  
   try
   {
    sr = new streamreader(temp, code);
    str = sr.readtoend(); // 讀取文件
   }
   catch(exception exp)
   {
    httpcontext.current.response.write(exp.message);
    httpcontext.current.response.end();
    sr.close();
   }
  
   
   string htmlfilename=datetime.now.tostring("yyyymmddhhmmss")+".html";
   // 替換內容
   // 這時,模板文件已經讀入到名稱為str的變量中了
   str =str.replace("showarticle",strtext); //模板頁中的showarticle
   str = str.replace("biaoti",strtext);
   str = str.replace("content",strcontent);
   str = str.replace("author",strauthor);
   // 寫文件
   try
   {
    sw = new streamwriter(path + htmlfilename , false, code);
    sw.write(str);
    sw.flush();
   }
   catch(exception ex)
   {
    httpcontext.current.response.write(ex.message);
    httpcontext.current.response.end();
   }
   finally
   {
    sw.close();
   }
   return true;

此函數放在conn.cs基類中了
在添加新聞的代碼中引用 注:工程名為hover

    if(hover.conn.writefilethis.title.text.tostring),this.content.text.tostring),this.author.text.tostring)))
    {
     response.write("添加成功");
    }
    else
    {
     response.write("生成html出錯!");
    } 
 


模板頁text.html代碼


  code:   
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
  <title>showarticle</title>
   <body>
biaoti
<br>
content<br>
author
</body>
</html>
biaoti
<br>
content<br>
author
</body>
</html> 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贡觉县| 北票市| 娱乐| 墨竹工卡县| 黑龙江省| 远安县| 安多县| 商洛市| 织金县| 余姚市| 拉孜县| 磐安县| 贡山| 徐州市| 汶上县| 年辖:市辖区| 色达县| 武威市| 车险| 格尔木市| 筠连县| 醴陵市| 繁昌县| 长治市| 卫辉市| 康保县| 同仁县| 宜川县| 常山县| 平阴县| 双流县| 尼玛县| 乌鲁木齐县| 颍上县| 临猗县| 澄迈县| 西吉县| 逊克县| 镇远县| 铜川市| 叶城县|