Asp. NET 정적 페이지 생 성 및 페이지 (글 내용 페이지) - NET 프로 그래 밍

주요 원 리 는 템 플 릿 의 특수 문 자 를 교체 하 는 것 이다.1. 정적 템 플 릿 페이지 template. html 는 주로 특수 문 자 를 정의 하여 교체 합 니 다.

 
  1. <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <divstyle="width:417px;height:54px"align="center">
  9. <br/>
  10. Title</div>
  11. <divstyle="width:417px;height:8px">
  12. <fontcolor="red"><scriptsrc="http://localhost/.Net/NewsFiles/ClickCount.aspx?NewsId=NewsId"></script></font> Time</div>
  13. <divstyle="width:417px;height:100px">
  14. Content</div>
  15. <divstyle="width:416px;height:9px">
  16. Pager</div>
  17. <divstyle="width:416px;height:8px">
  18. <formid="form1"action="../AddComment.aspx"style="margin:0px">
  19. <inputid="Text1"type="text"/><Imgid="Image1"src="http://www.dwww.cn/UserInfo/CheckCode.aspx"/><br/>
  20. <textareaid="CommentContent"cols="20"rows="2"></textarea>
  21. <br/>
  22. <inputid="NewsId"type="hidden"value="NewsId"/>
  23. <inputid="Button1"type="submit"value="button"/>
  24. <ahref="http://www.dwww.cn/News/Display.aspx?NewsId=NewsId"> </a></form>
  25. </div>
  26. </body>
  27. </html>

2. 전 태 페이지 뉴스 add. aspx 는 바로 하나의 양식 으로 뉴스의 제목 과 내용 을 작성 하 는 데 사용 된다.

 
  1. <%@PageLanguage="C#"AutoEventWireup="false"validateRequest="false"CodeFile="NewsAdd.aspx.cs"Inherits="NewsAdd.Admin_AdminPanel_NewsAdd"%>
  2. <%@RegisterTagPrefix="FCKeditorV2"Namespace="FredCK.FCKeditorV2"Assembly="FredCK.FCKeditorV2"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <htmlxmlns="http://www.w3.org/1999/xhtml">
  5. <headrunat="server">
  6. <title> </title>
  7. </head>
  8. <body>
  9. <formid="form1"runat="server">
  10. <div>
  11. <asp:LabelID="Label2"runat="server"Text=" "></asp:Label>
  12. <asp:TextBoxID="Title"runat="server"Width="325px"></asp:TextBox><br/>
  13. <asp:LabelID="Label1"runat="server"Text=" "></asp:Label>
  14. <FCKeditorV2:FCKeditorid="Content"basePath="~/FCKeditor/"runat="server"Height="400px"Width="70%"></FCKeditorV2:FCKeditor>
  15. <asp:ButtonID="Button1"runat="server"onClick="Button1_Click"Text="Button"/>
  16. <asp:LabelID="Message"runat="server"></asp:Label></div>
  17. </form>
  18. </body>
  19. </html>

3, 배경 페이지 뉴스 애 드. aspx. cs

 
  1. usingSystem;
  2. usingSystem.Data;
  3. usingSystem.Configuration;
  4. usingSystem.Collections;
  5. usingSystem.Web;
  6. usingSystem.Web.Security;
  7. usingSystem.Web.UI;
  8. usingSystem.Web.UI.WebControls;
  9. usingSystem.Web.UI.WebControls.WebParts;
  10. usingSystem.Web.UI.HtmlControls;
  11. usingMysqlserver;
  12. usingSystem.IO;
  13. usingSystem.Text;
  14. namespaceNewsAdd
  15. {
  16. publicpartialclassAdmin_AdminPanel_NewsAdd:System.Web.UI.Page
  17. {
  18. protectedvoidPage_Load(objectsender,EventArgse)
  19. {
  20. }
  21. protectedvoidButton1_Click(objectsender,EventArgse)
  22. {
  23. stringstrDate=DateTime.Now.ToString("yyMMdd")+"\"+DateTime.Now.ToString("yyyymmddhhmmss");
  24. stringstrFileName=strDate+".shtml";//
  25. stringstrTitle=Request.Form["Title"].ToString().Trim();//
  26. stringstrContent=Request.Form["Content"].ToString().Trim();//
  27. string[]content=strContent.Split(newChar[]{'|'});// ,
  28. intupbound=content.Length;//
  29. SqlServerDataBasedb=newSqlServerDataBase();
  30. boolsuccess=db.Insert("insertintoinNews(Title,Content,FilePath)values('"+strTitle+"','"+strContent+"','"+strFileName+"')",null);
  31. //if(success)
  32. //Message.Text=" !";
  33. /**////////////////////////////
  34. stringdir=Server.MapPath("../../"+"NewsFiles/"+DateTime.Now.ToString("yyMMdd"));//
  35. if(!Directory.Exists(dir))
  36. {
  37. Directory.CreateDirectory(dir);
  38. }
  39. /**////////////////////////////
  40. try
  41. {
  42. for(inti=0;i<content.Length;i++)
  43. {
  44. //string[]newContent=newstring[4];// html
  45. StringBuilderstrhtml=newStringBuilder();
  46. // StreamReader
  47. using(StreamReadersr=newStreamReader(Server.MapPath("../../"+"NewsFiles/")+"\template.html",Encoding.GetEncoding("gb2312")))
  48. {
  49. Stringoneline;
  50. // HTML
  51. while((oneline=sr.ReadLine())!=null)
  52. {
  53. strhtml.Append(oneline);
  54. }
  55. sr.Close();
  56. }
  57. //
  58. //SqlServerDataBasedb=newSqlServerDataBase();
  59. DataSetds=db.Select("selecttop1NewsIdfrominNewsorderbyNewsIddesc",null);// id
  60. stringstrTable="<table><tr><td>upUrl</td><td>Number</td><td>downUrl</td></tr></table>";// , upUrl( ),Number( ),downUrl( )
  61. // 。
  62. stringFilePath="";
  63. strhtml=strhtml.Replace("Title",strTitle);
  64. strhtml=strhtml.Replace("NewsId",ds.Tables[0].Rows[0]["NewsId"].ToString());
  65. strhtml=strhtml.Replace("Time",DateTime.Now.ToString("yyyy/MM/dd"));
  66. strhtml=strhtml.Replace("Content",content[i]);
  67. stringstrNumber="";// 1,2,3……
  68. for(intm=1;m<=upbound;m++)
  69. {
  70. if(m==1)// :20070524.shtml 20070524_1.shtml
  71. strNumber=strNumber+"["+"<ahref="+"../"+strDate+".shtml"+">"+m+"</a>"+"]";
  72. else
  73. {
  74. intn=m-1;// 20070524_2.shtml,
  75. strNumber=strNumber+"["+"<ahref="+"../"+strDate+"_"+n+".shtml"+">"+m+"</a>"+"]";
  76. }
  77. }
  78. if(upbound==0)// ,
  79. {
  80. FilePath=Server.MapPath("../../")+"NewsFiles"+"//"+strDate+".shtml";
  81. strhtml=strhtml.Replace("Pager","");
  82. }
  83. else// 20070524.shtml、20070524_1.shtml
  84. {
  85. if(i==0)
  86. FilePath=Server.MapPath("../../")+"NewsFiles"+"//"+strDate+".shtml";
  87. else
  88. FilePath=Server.MapPath("../../")+"NewsFiles"+"//"+strDate+"_"+i+".shtml";
  89. if(i==0)//
  90. strTable=strTable.Replace("upUrl","");
  91. if(i<=1)//
  92. strTable=strTable.Replace("upUrl","<ahref="+"../"+strDate+".shtml"+"> </a>");
  93. else
  94. {
  95. intp=i-1;
  96. strTable=strTable.Replace("upUrl","<ahref="+"../"+strDate+"_"+p+".shtml"+"> </a>");
  97. }
  98. if(upbound==1)// ,
  99. //strNumber="";
  100. strTable=strTable.Replace("Number","");
  101. else
  102. strTable=strTable.Replace("Number",strNumber);//
  103. /**/////////////////////////
  104. if(i==upbound-1)//
  105. strTable=strTable.Replace("downUrl","");
  106. if(i!=upbound-1)//
  107. {
  108. intq=i+1;
  109. strTable=strTable.Replace("downUrl","<ahref="+"../"+strDate+"_"+q+".shtml"+"> </a>");
  110. }
  111. else
  112. {
  113. intj=upbound-1;
  114. strTable=strTable.Replace("downUrl","<ahref="+"../"+strDate+"_"+j+".shtml"+"> </a>");
  115. }
  116. strhtml=strhtml.Replace("Pager",strTable);
  117. }
  118. // --------------------------------------------
  119. FileInfofinfo=newFileInfo(FilePath);
  120. //
  121. using(FileStreamfs=finfo.OpenWrite())
  122. {
  123. //
  124. StreamWritersw=newStreamWriter(fs,System.Text.Encoding.Default);
  125. // HTML
  126. sw.WriteLine(strhtml);
  127. sw.Flush();
  128. sw.Close();
  129. }
  130. }
  131. }
  132. catch(Exceptionerr)
  133. {
  134. //
  135. Response.Write(err.ToString());
  136. }
  137. }
  138. }
  139. }

좋은 웹페이지 즐겨찾기