版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、1)做一個(gè)比較好的模板temp1.html ,并在模板中寫好題目,內(nèi)容,作者以及發(fā)布日期的標(biāo)記,如果還有其他列表的話也要寫好其他列表的標(biāo)記,如題目可以用標(biāo)記:$Title$,內(nèi)容可以用$cont$,發(fā)布日期$PubDate ,最新發(fā)布新聞列表$DtNewest$ ;2)設(shè)計(jì)數(shù)據(jù)庫,可以設(shè)置兩張表,一張表存放模板,一張用于存放發(fā)布新聞的內(nèi)容 using System.Web.UI;如模板表:TempTableID ,classid,TempPath(存放模板的路徑);新聞表: NesTable: 徑) ,pubdate,author,status;ID,ClasslD,title,cont,Fi
2、lepath(發(fā)布后存放靜態(tài)頁面的路3)添加新聞時(shí),現(xiàn)在記錄添加到新聞表中,然后再根據(jù)欄目的 取到一個(gè)字符串變量中, 到一個(gè)靜態(tài)文件中如:ID找到該欄目的模板,把模板中的內(nèi)容讀 并用新聞表中的字段替換模板中的相應(yīng)標(biāo)記,然后調(diào)用c#中的讀寫文件的類,寫News.HTml ,寫成功后再更新數(shù)據(jù)中靜態(tài)文件路徑filepath;這樣一個(gè)靜態(tài)文件就寫好了另外本人也從網(wǎng)絡(luò)上搜集了一些資料,供大家參考(關(guān)于新聞內(nèi)容分頁的情況下次敘述)一、類似的模板模板頁Text.html 代碼<!DOCTYPE HTML PUB LIC "-/W3C/DTD HTML 4.0 Transitional/EN
3、" > <HTML><HEAD><title>$ShowArticle$v/title><body>$title$<br>$author$<br>$content$<br></body></HTML>二、C#生成靜態(tài)頁類代碼|支持列表生成代碼using System;using System.Data;using System.Configuration;using System.Web;usi ng System.Web.Ul.WebC on trols;us i
4、ng System.Web.Ul.WebCo ntrols.WebParts;usi ng System.Web.Ul.HtmICo ntrols;using zj123.Model;using Syste m.IO;using System.Text.RegularExpressi ons;using System.R un time.I nteropServices;using System.Text;using System.Collectio ns;n amespace WebUI.htmlpublic class EasyHtmlpublic bool MakeHtml(stri n
5、g artid)bool succ = false;in t le n =Conv ert.ToI nt32(C on vert.ToStri ng(System.Co nfigurati on .C on figurati onMan ager.AppSetti ngs"titlele ngth") ? "20");/讀取數(shù)據(jù)stri ng sql = stri ng.Format("selecta. *,b.ClassName,b.Depth,b.OrderBy,b.isTop,b.isList,b.lsL in ks,b.Li nks,b
6、. PicURL,b.Pare ntlD,b.Templateoutld,b.Templatei nN eild,b.Templatei nLis tId from article a,zone b where a.classid=b.classid and a.Status=3 and a.articleid=0", artid);DataTable dt = DbHelperOleDb.Query(sql).Tables0; if(dt.Rows.Cou nt>0)/外模板stri ng waitemp =""DataTablewaidt =DbHelp
7、erOleDb.Query(string.Format("select* from template whereTemplatelD=0",Co nvert.ToStri ng(dt.Rows0"TemplateoutId").Trim() ).Tables0;if (waidt.Rows.Cou nt > 0)waitemp =Con vert.ToStri ng(waidt.Rows0"TemplateCo nten t");/內(nèi)模板stri ng n eitemp =""DataTable neidt
8、= DbHelperOleDb.Query(string.Format("select * from template where TemplatelD=0", Convert.ToString(dt.Rows0TemplateinNeild").Trim().Tables0;if (neidt.Rows.Count > 0)neitemp = Convert.ToString(neidt.Rows0TemplateContent");/替換模板waitemp = waitemp.Replace("$intemplate$",
9、neitemp);/替換類型string tempclassname = classes.Common.GetP(Convert.ToString(dt.Rows0classid");waitemp = waitemp.Replace("$ClassName$", tempclassname);#region "文章列表"/最新的文章System.Text.StringBuilder sbneartitle = new System.Text.StringBuilder("<div align="left"&
10、gt;");DataTable nearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + " then substring(title,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 order by updatetime desc").Tables0;for (int i = 0; i < nearTit
11、ledt.Rows.Count; i+)sbneartitle.AppendFormat("vli><a href="0">1v/a>v/li>",Convert.ToString(nearTitledt.RowsiHtmlPath"),Convert ToString(nearTitledt.RowsiTitle");sbneartitle.Append("</ol>v/div>");waitemp = waitemp.Replace("$NearTitl
12、e$", sbneartitle.ToString(); sbneartitle.Remove(0,sbneartitle.ToString (). Length);if (waitemp.Contains("$OnTopTitle$")sbneartitle.Append("<div align="left">");/固定nearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + &qu
13、ot; then substring(title,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 and OnTop=1 order by updatetime desc").Tables0;for (int i = 0; i < nearTitledt.Rows.Count; i+)sbneartitle.AppendFormat("<li><a href="0">1</a></
14、li>", Convert.ToString(nearTitledt.Rowsi"HtmlPath"), Convert.ToString(nearTitledt.Rowsi"Title");sbneartitle.Remove(0, sbneartitle.ToString().Length);sbneartitle.Append("v/ol>v/div>");waitemp = waitemp.Replace("$OnTopTitle$", sbneartitle.ToString(
15、); sbneartitle.Remove(0, sbneartitle.ToString().Length);if (waitemp.Contains("$HitsTitle$")sbneartitle.Append("<div align="left">");/熱門nearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + " then substring(title,1,"
16、 + len + ") else title end as Title,HtmlPath from article where iscreate=1 and Hits>1000 order by Hits desc,updatetime desc").Tables0;for (int i = 0; i < nearTitledt.Rows.Count; i+)sbneartitle.AppendFormat("<li><a href="0">1</a>v/li>", Convert
17、.ToString(nearTitledt.Rowsi"HtmlPath"), Convert.ToString(nearTitledt.Rowsi"Title");sbneartitle.Append("</ol>v/div>");waitemp = waitemp.Replace("$HitsTitle$", sbneartitle.ToString();sbneartitle.Remove(0, sbneartitle.ToString().Length);if (waitemp.Conta
18、ins("$Elite$")sbneartitle.Append("<div align="left">");/ 推薦 ElitenearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + " then substring(title,1," + len + ") else title end as Title,HtmlPath from article where i
19、screate=1 and Elite=1 order by updatetime desc").Tables0;for (int i = 0; i < nearTitledt.Rows.Count; i+)sbneartitle.AppendFormat("<li><a href="0">1</a></li>", Convert.ToString(nearTitledt.Rowsi"HtmlPath"), Convert.ToString(nearTitledt.Row
20、si"Title");sbneartitle.Append("</ol>v/div>");waitemp = waitemp.Replace("$Elite$", sbneartitle.ToString();sbneartitle.Remove(0, sbneartitle.ToString().Length);/ 相關(guān) Classidif (waitemp.Contains("$ClassTitle$")sbneartitle.Append("<div align="
21、left">");nearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" len + " then substring(title,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 and classid=" + Convert.ToString(dt.Rows0"classid") + &q
22、uot; order by updatetime desc").TablesO;for (int curr = 0; curr < nearTitledt.Rows.Count; curr+)sbneartitle.AppendFormat("vli>va href="0">1v/a>v/li>", Convert.ToString(nearTitledt.Rowscurr"HtmlPath"), Convert.ToString(nearTitledt.Rowscurr"Title&
23、quot;);sbneartitle.Append("v/ol>v/div>");waitemp = waitemp.Replace("$ClassTitle$", sbneartitle.ToString();sbneartitle.Remove(O, sbneartitle.ToString().Length);/ 相關(guān) Classidif (waitemp.Contains("$LikeTitle$")sbneartitle.Append("<div align='left'>&
24、quot;);DataTable dtlike = zj123.Model.Article.GetLike(artid);for (int likei = 0; likei < dtlike.Rows.Count; likei+)sbneartitle.AppendFormat("<li><a href="0">1</a></li>", Convert.ToString(dtlike.Rowslikei"HtmlPath"), Convert.ToString(dtlike.Row
25、slikei"Title");sbneartitle.Append("</ol>v/div>");waitemp = waitemp.Replace("$LikeTitle$", sbneartitle.ToString();sbneartitle.Remove(0, sbneartitle.ToString().Length);/#endregion/替換最新的數(shù)據(jù)for (int j = 0; j < dt.Columns.Count; j+)if (dt.Columnsj.ColumnName.Trim(
26、) = "Title")string tempi =""string temp2 =""string typefont = Convert.ToString(dt.Rows0TitleFontType");if (typefont = "0")temp1 = "<strong>"temp2 = "v/stro ng>"else if (typefont = "1")tempi = "<em>"te
27、mp2 = "</em>"else if (typefont = "2")tempi = "<stro ng><em>"temp2 = "</strong>v/em>"else/System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex();/Match match = Regex.Matches();reg.Replace(waitemp, Conver
28、t.ToString(dt.Rows0dt.Columnsj.ColumnName.Trim(), 1, waitemp.lndexOf("$Title$");string templl = waitemp.Substring(0, waitemp.IndexOf("$Title$") + 8);string temp22 = waitemp.Substring(waitemp.lndexOf("$Title$") + 8);templl = temp11.Replace("$Title$", Convert.To
29、String(dt.Rows0dt.Columnsj.ColumnName.Trim()+"-"+Regex.Replace(R egex.Replace(tempclassname,"vA>*>",""),">|<*","");temp22 = temp22.Replace("$Title$", "vfont color='" +Convert.ToString(dt.Rows0"TitleFontColor&q
30、uot;) + "'>" + tempi +Convert.ToString(dt.Rows0dt.Columnsj.ColumnName.Trim() + temp2 + "</font>");waitemp = tempii + temp22;tempii = null;temp22 = null;/waitemp = waitemp.Replace("$" + dt.Columnsj.ColumnName.Trim()+ "$", "vfont color='&qu
31、ot; + Convert.ToString(dt.Rows0"TitleFontColor") + "'>" +tempi +Convert.ToString(dt.Rows0dt.Columnsj.ColumnName.Trim() +temp2+ "</font>");else if (dt.Columnsj.ColumnName.Trim().ToLower() = "hits")熱門"):waitemp = waitemp.Replace(”$" + dt.C
32、olumnsj.ColumnName.Trim()+ "$", Convert.Tolnt16(dt.Rows0dt.Columnsj.ColumnName.Trim() > 1000 ?("("");else if (dt.Columnsj.ColumnName.Trim().ToLower() = "ontop")waitemp = waitemp.Replace("$" + dt.Columnsj.ColumnName.Trim()+ "$", Convert.ToStri
33、ng(dt.Rows0dt.Columnsj.ColumnName.Trim().ToLower()="true" ?(" 置頂"):("");else if (dt.Columnsj.ColumnName.Trim().ToLower() = "elite")waitemp = waitemp.Replace("$" + dt.Columnsj.ColumnName.Trim()+ "$",Convert.ToString(dt.Rows0dt.Columnsj.Colum
34、nName.Trim().ToLower().ToString()="true" ?(" 推薦"):("");elsewaitemp = waitemp.Replace("$" + dt.Columnsj.ColumnName.Trim()+ "$", Convert.ToString(dt.Rows0dt.Columnsj.ColumnName.Trim();/替換鏈表信息/$typejs$waitemp = waitemp.Replace("$typejs$", Conv
35、ert.ToString(dt.Rows0"ClassID");/$numjs$waitemp = waitemp.Replace("$numjs$", "10");/$setjs$waitemp = waitemp.Replace("$setjs$","");/js 腳本信息/根據(jù)路徑生成頁面/路徑檢查string path =System.Web.HttpContext.Current.Request.PhysicalApplicationPath.Trim()+Convert.ToStri
36、ng(dt.Rows0"Links") + "" +Convert.ToDateTime(dt.Rows0CreateTime").ToString("yyyy-MM");if(!Directory.Exists(path)Directory.CreateDirectory(path);string filename = ""+ Convert.ToString(dt.Rows0ArticlelD") + ".html"using(StreamWriter sw = new
37、StreamWriter(path+""+filename,false,System.Text.Encoding.GetEncoding("gb2312")sw.Write(waitemp);sw.Flush();sw.Close();/修改文章轉(zhuǎn)臺tryif (artid = null)return false;int j = int.Parse(artid);catchreturn false;string sql1 = string.Format("update article set iscreate=1,htmlpath='0
38、' where articleid=1", "/" + Convert.ToString(dt.Rows0"Links").Replace("", "/") + "/" + Convert.ToDateTime(dt.Rows0"CreateTime").ToString("yyyy-MM") + filename, artid);DbHelperOleDb.ExecuteSql(sqll);elsereturn false;return
39、 succ;/ <summary>/生成列表頁/ </summary>/ <param name="classid"></param>/ <returns>v/returns>public bool MakeList(string classid)int len = Convert.Tolnt32(Convert.ToString(System.Configuration.ConfigurationManager.AppSetting s"titlelength") ? "20&
40、quot;);bool succ = false;tryint i = int.Parse(classid);catchreturn false;DataTable dt = DbHelperOleDb.Query(string.Format("selecta. *,b.ClassName,b.Depth,b.OrderBy,b.isTop,b.isList,b.lsLinks,b. Links,b.PicURL,b.ParentlD,b. Templateoutlistld,b.Templateoutld,b.TemplateinNeild,b.TemplateinListld,b
41、.keywords,b.description from article a,zone bwhere a.classid=b.classid andiscreate=1 anda.Status=3 and a.classid=0 order by a.UpdateTime desc,OnTop desc,Elite desc,Hits desc", classid).Tables0;if (dt.Rows.Count > 0)string classpath = HttpContext.Current.Request.PhysicalApplicationPath + &quo
42、t;"+ Convert.ToString(dt.Rows0"Links").Trim();/讀取外模板信息string templatewai =""DataTable templatewaidt = DbHelperOleDb.Query(string.Format("select * from template where TemplatelD=0", Convert.ToString(dt.Rows0"Templateoutlistld").Tables0;if (templatewaidt.Ro
43、ws.Count > 0)templatewai =Convert.ToString(templatewaidt.Rows0"TemplateContent");/根據(jù)類型替換標(biāo)題string tempclassname = classes.Common.GetP(classid);templatewai = templatewai.Replace("$Title$", Convert.ToString(dt.Rows0"ClassName").Trim() +"-"+Regex.Replace(Regex.
44、Replace(tempclassname,"vA>*>",'"'),"v|>*","");templatewai = templatewai.Replace("$ClassTitleTop$", Convert.ToString(dt.Rows0"ClassName").Trim();templatewai = templatewai.Replace("$ClassName$", tempclassname);templatewa
45、i = templatewai.Replace("$Keyword$", Convert.ToString(dt.Rows0"Keywords").Trim();templatewai = templatewai.Replace("$Description$",Convert.ToString(dt.Rows0Description").Trim();int zong = dt.Rows.Count;int size = 10;trysize =Convert.Tolnt16(System.Configuration.Con
46、figurationManager.AppSettings"pagesize");catchsize = 10;int pagecount = zong % size = 0 ? (zong / 10) : (zong / 10 + 1);string listcontent =""DataTable dtlist = DbHelperOleDb.Query(string.Format("select * from templatewhere TemplatelD=0", Convert.ToString(dt.Rows0Templa
47、teinListld").Tables0;if (dtlist.Rows.Count > 0)listcontent = Convert.ToString(dtlist.Rows0TemplateContent");/ Match mat = Regex.Match(this.rtbconten.Text.Trim(),"vtablehead>(?<content>.*)vtableheadend>vtablebody>v/tablebodyend>vtablepage> v/tablepage><tab
48、lebottom>v/tablebottomend>", RegexOptions.Multiline |RegexOptionsgnoreCase);/ MessageBox.Show(mat.Groups"content".Value);/vtablehead>(?vcontent>.*)vtableheadend>vtablebody>v/tablebodyend> vtablepage>v/tablepage>vtablebottom>v/tablebottomend>/Match mat
49、= Regex.Match(listcontent,"vtablehead>(?vhead>.*)vtableheadend>vtablebody>(?vbody>.*)v/tablebodyend>vta blepage>(?vpage>.*)v/tablepage>vtablebottom>(?vbottom>.*)v/tablebottomend>",Re gexOptionsgnoreCase|RegexOptions.Multiline);string head = Convert.ToStr
50、ing(mat.Groups"head");string body = Convert.ToString(mat.Groups"body");string page = Convert.ToString(mat.Groups"page");string bottom = Convert.ToString(mat.Groups"bottom");/循環(huán)生成分頁for (int i = 0; i v pagecount; i+)/System.Text.StringBuilder sbneilist = newSyst
51、em.Text.StringBuilder("vTABLE cellSpacing=0 cellPadding=0 width=760border=0><TBODY>");System.Text.StringBuilder sbneilist = new System.Text.StringBuilder(head);int l = 0;for (int j = (i * size < zong) ? (i * size) : (zong); j < (i + 1) * size < zong ? (i+ 1) * size) : (zo
52、ng); j+)/sbneilist.Append(” <TR><TD vAlign=top align=centerbgColor=#f7f7f7 >");/string temp = listcontent;string temp = body;for (int k = 0; k < dt.Columns.Count; k+)temp = temp.Replace("$" + dt.Columnsk.ColumnName.Trim() + "$",Convert.ToString(dt.Rowsjdt.Colu
53、mnsk.ColumnName.Trim();if (+l) % 5 = 0)sbneilist.Append(temp).Append("<dd class="l"></dd>");elsesbneilist.Append(temp);sbneilist.Append("v/td>v/tr>");/sbneilist.Append("<TR><TDheight=36>").Append(classes.Common.GetPage(i + 1, size
54、, zong).Append("</td></tr>");sbneilist.Append(page.Replace("¥ pages ¥", classes.Common.GetPage(i + 1,size, zong);/ sbneilist.Append("</tbody>v/table>");sbneilist.Append(bottom);#region "文章列表"/最新的文章System.Text.StringBuilder sbnear
55、title = new System.Text.StringBuilder("");DataTable nearTitledt = DbHelperOleDb.Query("select top 10 case whenlen(title)>" + len + " then substring(title,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 order by updatetime desc"
56、).TablesO;for (int curr = 0; curr < nearTitledt.Rows.Count; curr+)sbneartitle.AppendFormat("<li><a href="0">1v/a>v/li>",Convert.ToString(nearTitledt.Rowscurr"HtmlPath"), Convert.ToString(nearTitledt.Rowscurr"Title");sbneartitle.Append(&quo
57、t;");templatewai = templatewai.Replace("$NearTitle$", sbneartitle.ToString();sbneartitle.Remove(0, sbneartitle.ToString().Length);sbneartitle.Append("");/固定nearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + " then substring(titl
58、e,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 and OnTop=1 order by updatetime desc").Tables0;for (int curr = 0; curr < nearTitledt.Rows.Count; curr+)sbneartitle.AppendFormat("<li><a h-ref="0">1</a></li>",
59、Convert.ToString(nearTitledt.Rowscurr"HtmlPath"), Convert.ToString(nearTitledt.Rowscurr"Title");sbneartitle.Remove(0, sbneartitle.ToString().Length);sbneartitle.Append("");templatewai = templatewai.Replace("$OnTopTitle$", sbneartitle.ToString();sbneartitle.Rem
60、ove(0, sbneartitle.ToString().Length);sbneartitle.Append("");/熱門nearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + " then substring(title,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 and Hits>1000
61、order by Hits desc,updatetime desc").Tables0;for (int curr = 0; curr < nearTitledt.Rows.Count; curr+)sbneartitle.AppendFormat("<li><a href="0">1</a></li>",Convert.ToString(nearTitledt.Rowscurr"HtmlPath"), Convert.ToString(nearTitledt.Rows
62、curr"Title");sbneartitle.Append("");templatewai = templatewai.Replace("$HitsTitle$", sbneartitle.ToString();sbneartitle.Remove(0, sbneartitle.ToString().Length);sbneartitle.Append("");/ 推薦 ElitenearTitledt = DbHelperOleDb.Query("select top 10 case when len(title)>" + len + " then substring(title,1," + len + ") else title end as Title,HtmlPath from article where iscreate=1 and Elite=1 order by updatetime desc").TablesO;for (int curr = 0; curr < nearTitledt.Rows.Count; curr+) sbneartitle.AppendFormat("<li>&
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 解除建設(shè)合同協(xié)議
- 公司對公短期借款合同格式
- 燈具供應(yīng)協(xié)議
- 英文版設(shè)備采購合同
- 家居家具選購合同
- 質(zhì)量保證書質(zhì)量領(lǐng)先服務(wù)至上
- 聘用合同補(bǔ)充協(xié)議樣本
- 嚴(yán)謹(jǐn)作風(fēng)自覺加班
- 服務(wù)推廣合作合同書
- 招標(biāo)前期物業(yè)服務(wù)合同
- 2024年初中七年級英語上冊單元寫作范文(新人教版)
- 新編蘇教版一年級科學(xué)上冊實(shí)驗(yàn)報(bào)告冊(典藏版)
- 醫(yī)學(xué)免疫學(xué)-醫(yī)學(xué)檢驗(yàn)專業(yè)學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 獨(dú)立基礎(chǔ)土方開挖施工方案
- 【基于單片機(jī)的電子密碼鎖設(shè)計(jì)(論文)10000字】
- 腫瘤病人常見癥狀護(hù)理
- 瑜伽基礎(chǔ)知識題庫單選題100道及答案解析
- 廣東省廣州市2024年中考數(shù)學(xué)真題試卷(含答案)
- 2024年資格考試-注冊質(zhì)量經(jīng)理考試近5年真題附答案
- 浙江省臺州市2023-2024學(xué)年七年級上學(xué)期期末數(shù)學(xué)試題(含答案)
- 2024年秋季國家開放大學(xué)《形勢與政策》大作業(yè)及答案
評論
0/150
提交評論