随笔- 68  评论- 89  文章- 0 

生成静态页方式一


“生成静态页”,已成为时尚了,无论什么类型的网站,似乎都开始采用这种方式,下面介绍的是其中的一种方法。下面是部分核心代码,,,意思到了。。。应该很容易看懂~
public bool HtmlOutUnit(int Top_Setting_ID,string ModelPath,string IncludePath)
  {
   Model.Setting model = Business.Setting.GetModel(Top_Setting_ID);
   
   //输出目录
   string OutDir = "html\\Setting\\"+model.Top_Setting_Reldate.ToString("yyyyMMdd");
   //------------------------------------------------------------------------------------------------------------
   StringBuilder HtmlStr = new StringBuilder();
   Top.Common.IO.File.Read(System.Web.HttpContext.Current.Request.PhysicalApplicationPath+ModelPath,out HtmlStr,System.Text.Encoding.GetEncoding("gb2312"));
   string direct = System.Web.HttpContext.Current.Request.PhysicalApplicationPath+OutDir;
   if(!System.IO.Directory.Exists(direct))
   {
    System.IO.Directory.CreateDirectory(direct);
   }

   string Path = direct+"\\"+Top.Common.Security.Cryptography.DBSaltedPassword.GetMd5(model.Top_Setting_ID.ToString())+".html";
   string Pic = "";
   if(model.Top_Setting_Picture != "")
   {
   
    Pic = "<div align=\"center\" style=\"PADDING-RIGHT:15px;PADDING-LEFT:15px;PADDING-BOTTOM:15px;PADDING-TOP:15px\"><img src=\"../../../"+model.Top_Setting_Picture+"\" width=\"380\" height=\"272\"></div>";
   }

   HtmlStr = HtmlStr.Replace("$Setting_ID$",model.Top_Setting_ID.ToString());
   HtmlStr = HtmlStr.Replace("$展会图片$",Pic);
   HtmlStr = HtmlStr.Replace("$发布者$",model.Top_Setting_Username);
   HtmlStr = HtmlStr.Replace("$发布时间$",model.Top_Setting_Reldate.ToString());
   HtmlStr = HtmlStr.Replace("$展会名称$",model.Top_Setting_Name);
   HtmlStr = HtmlStr.Replace("$会展地址$",model.Top_Setting_address);
   HtmlStr = HtmlStr.Replace("$主办单位$",model.Top_Setting_Sponsor);
   HtmlStr = HtmlStr.Replace("$承办单位$",model.Top_Setting_Organizer);
   HtmlStr = HtmlStr.Replace("$协办单位$",model.Top_Setting_Hand);
   HtmlStr = HtmlStr.Replace("$支持单位$",model.Top_Setting_Sustain);
   HtmlStr = HtmlStr.Replace("$支持媒体$",model.Top_Setting_Media);
   HtmlStr = HtmlStr.Replace("$地区$",model.Top_Province_Name);
   HtmlStr = HtmlStr.Replace("$会展介绍$",model.Top_Setting_About);
   HtmlStr = HtmlStr.Replace("$会展服务$",model.Top_Setting_Server);
   HtmlStr = HtmlStr.Replace("$截止日期$",model.Top_Setting_Enddate);
   HtmlStr = HtmlStr.Replace("$参展费用$",model.Top_Setting_Charge);
   
   HtmlStr = HtmlStr.Replace("$Logo$","hzxx.gif");
   HtmlStr = HtmlStr.Replace("$LogoString$","<font style=\"font-weight:bold;\">HuiZhangXinXi</font>");
   HtmlStr = HtmlStr.Replace("$导航菜单$",ComScript("../../../script/request/navmenu.aspx"));
   HtmlStr = HtmlStr.Replace("$导航消息$",ComScript("../../../script/request/navmessage.aspx"));
   HtmlStr = HtmlStr.Replace("$心情寄语$",ComScript("../../../script/request/mood_0.aspx"));
   HtmlStr = HtmlStr.Replace("$推荐企业$",ComScript("../../../script/request/company_0.aspx"));
   HtmlStr = HtmlStr.Replace("$合作伙伴$",ComScript("../../../script/request/together.aspx"));
   HtmlStr = HtmlStr.Replace("$最新求购$",ComScript("../../../script/request/hoping_0.aspx"));
   HtmlStr = HtmlStr.Replace("$最新供应$",ComScript("../../../script/request/provide_0.aspx"));
   HtmlStr = HtmlStr.Replace("$页脚$",ComScript("../../../script/request/footer.aspx"));
 
   HtmlStr = HtmlStr.Replace("$广告1$",ComScript("../../../script/request/ad_0.aspx"));
   HtmlStr = HtmlStr.Replace("$广告2$",ComScript("../../../script/request/ad_1.aspx"));
   HtmlStr = HtmlStr.Replace("$广告4$",ComScript("../../../script/request/ad_3.aspx"));
   HtmlStr = HtmlStr.Replace("$广告5$",ComScript("../../../script/request/ad_4.aspx"));
   //---------------------------------------------------------------------------------
   
   Top.Common.IO.File.Write(Path,HtmlStr,Encoding.GetEncoding("gb2312"));
   model.Top_Setting_Key = SetKey(model.Top_Setting_Key,2,'1');
   model.Top_Setting_Link = OutDir+"\\"+Top.Common.Security.Cryptography.DBSaltedPassword.GetMd5(model.Top_Setting_ID.ToString())+".html";
   Update(model);
   return true;
  }

posted on 2007-06-07 16:31 噢耶游戏 阅读(...) 评论(...) 编辑 收藏