public static void CreateNewsHtml(String newsId, String fileName, bool checkExists) { if ((!checkExists) || (!System.IO.File.Exists(fileName))) { var news = new BLL.news.V_NewsInfo().GetModel(Int64.Parse(newsId)); if (news != null) { // 读取模板文件 string temp = HttpContext.Current.Server.MapPath("/home/news/template/news_template.html"); String newsStr = FileOperate.ReadFile(temp); newsStr = newsStr.Replace("titlexxx", news.NI_Tile); StringBuilder sb = new StringBuilder(); if (news.UI_RealName != "") { sb.Append("<span>发布者:").Append(news.UI_RealName).Append("</span>"); } var isCampusCol = IsCampusCol(news.NCh_Id); if (isCampusCol) { var newsChannel = new BLL.news.News_NewsChannel().GetModel(news.NCh_Id); //content += "<p>来源:<a href='" + newsChannel.NCh_RssUrl + "'>" + newsChannel.NCh_Name + "</a></p>"; sb.Append(" <span>来源:" + newsChannel.NCh_Name + "</span>"); } sb.Append(" "); sb.Append(news.CN_PubDate); //sb.Append(" ").Append("阅读次数:").Append(news.NI_ReadNum); newsStr = newsStr.Replace("desxxx", sb.ToString()); String content = HttpContext.Current.Server.HtmlDecode(news.NI_Content); //newsStr = newsStr.Replace("contentxxx", content); newsStr = newsStr.Replace("contentxxx", NewsHelper.SetHtmlImgWidth(content, "98%", "")); sb.Clear(); var newsAttach = new BLL.news.News_NewsInfo().GetModel(Int64.Parse(newsId)).NewsAttach; if (newsAttach != null && newsAttach.Count > 0) { sb.Append("<p class='attachTitle'>附件:</p>"); var itemCnt = 1; foreach (var item in newsAttach) { sb.Append("<p class='attachItem'>(").Append(itemCnt).Append(") <a href='") .Append("/home/news/Attach.aspx?id=").Append(DESEncrypt.Encrypt(item.NA_Id.ToString())) .Append("&address=").Append(HttpUtility.UrlEncode(item.NA_Address)) .Append("&name=").Append(HttpUtility.UrlEncode(item.NA_Name)) .Append("' target='_blank' >") .Append(item.NA_Name) .Append("</a>") .Append(OnlineViewHelper.GetOnlineViewWrapLink(item.NA_Address, item.NA_Name)) .Append("</p>"); itemCnt++; } } newsStr = newsStr.Replace("attachxxx", sb.ToString()); //写文件 FileOperate.WriteNewFile(fileName, newsStr); } } }