ASP tutorial. NET generates static pages and pagination
<!doctype HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>title </title>
<body>
<div style= "WIDTH:417PX; height:54px "align=" Center ">
<br/>
Title
</div>
<div style= "WIDTH:417PX; Height:8px ">
Browse <font color= "Red" >
<script src= "Http://localhost/.net/newsfiles/clickcount.aspx?newsid=newsid" > </script>
</font> time
</div>
<div style= "WIDTH:417PX; height:100px ">
Content
</div>
<div style= "WIDTH:416PX; Height:9px ">
Pager
</div>
<div style= "WIDTH:416PX; Height:8px ">
<form id= "Form1" action= ". /addcomment.aspx "style=" margin:0px ">
<input id= "Text1" type= "text"/>
<img id= "Image1" src= "http://www.0379zd.com/userinfo/checkcode.aspx"/>
<br/>
<textarea id= "commentcontent" cols= "rows=" "2" > </textarea>
<br/>
<input id= "NewSID" type= "hidden" value= "NewSID"/>
<input id= "Button1" type= "Submit" value= "button"/>
<a href= "Http://www.0379zd.com/news/display.aspx?newsid=newsid" > see more reviews </a>
</form>
</div>
</body>
</html>
2, the Front state page newsadd.aspx, is a form, used to fill in the headlines and content of the news.
Code
<%@ page language= "C #" autoeventwireup= "false" validaterequest= "false" codefile= "Newsadd.aspx.cs" inherits= " Newsadd.admin_adminpanel_newsadd "%>
<%@ register tagprefix= "Fckeditorv2" namespace= "Fredck.fckeditorv2" assembly= "Fredck.fckeditorv2"%>
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head id= "Head1" runat= "Server" >
<title> Add News </title>
</head>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:label id= "Label2" runat= "Server" text= "title" > </asp:label>
<asp:textbox id= "title" runat= "Server" width= "325px" > </asp:textbox>
<br/>
<asp:label id= "Label1" runat= "server" text= "Content" > </asp:label>
<fckeditorv2:fckeditor id= "Content" basepath= "~/fckeditor/" runat= "Server" height= "400px" width= "70%" >
</fckeditorv2:fckeditor>
<asp:button id= "button1" runat= "Server" onclick= "Button1_Click" text= "button"/>
<asp:label id= "message" runat= "Server" > </asp:label>
</div>
</form>
</body>
</html>
3, background page Newsadd.aspx.cs
Code
using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.web.ui.webcontrols.webparts;
Using System.Web.UI.HtmlControls;
using MySQL tutorial server;
Using System.IO;
Using System.Text;
Namespace Newsadd
{
public partial class Admin_adminpanel_newsadd:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e)
{
String strdate = DateTime.Now.ToString ("YYMMDD") + "" + datetime.now.tostring ("Yyyymmddhhmmss");
String strFileName = Strdate + ". shtml";//stored in the database tutorial
String strtitle = request.form["title"].tostring (). Trim ();//Receive the caption passed over
String strcontent = request.form["Content"].tostring (). Trim ();//Receive transmitted content
string[] content = Strcontent.split (new char[] {' | '}); /splits the content and saves it to the array
int upbound = Upper bound of content.length;//array
Sqlserverdatabase db = new Sqlserverdatabase ();
BOOL success = Db.insert ("INSERT into innews (Title,content,filepath) VALUES (' + strtitle +" ', ' "+ strcontent +" ', ' "+ st Rfilename + "')", null);
if (success)
Message.Text = "Add success!" ";
/**/
Start the folder where the current date is created
String dir = Server.MapPath ("http://www.cnblogs.com/" + "newsfiles/" + datetime.now.tostring ("YYMMDD"));//to generate a folder
if (!directory.exists (dir))
{
Directory.CreateDirectory (dir);
}
/**/
End of folder creating current date
Try
{
for (int i = 0; i < content.length; i++)
{
string[] newcontent = new string[4];//definition and an array with a consistent number of HTML tags
StringBuilder strhtml = new StringBuilder ();
Creating StreamReader objects
using (StreamReader sr = new StreamReader (Server.MapPath ("http://www.cnblogs.com/" + "newsfiles/") + "template.html", Encoding.GetEncoding ("gb2312"))
{
String oneline;
Read the specified HTML file template
while ((Oneline = Sr.readline ())!= null)
{
Strhtml.append (oneline);
}
Sr.close ();
}
//Assigning values to the array of tokens
//sqlserverdatabase db = new Sqlserverdatabase ();
DataSet ds = Db.select ("Select top 1 NewSID to Innews ORDER by newsid DESC", null);/get ID
string strtable = "<table> <tr> <td>upurl </td> <td>number </td> <td>downurl </td > </tr> </table> "//Up and down page table, note here Upurl (previous), number (page pagination), Downurl (Next page)
//These three are used for replacement.
string filepath = "";
strHTML = Strhtml.replace ("title", strtitle);
strHTML = Strhtml.replace ("NewSID", ds.tables[0].rows[0]["NewSID"].tostring ());
strHTML = Strhtml.replace ("Time", DateTime.Now.ToString ("Yyyy/mm/dd"));
strHTML = Strhtml.replace ("Content", content[i]);
String strnumber = "";//Digital Paging 1,2,3 ...
for (int m = 1; M <= upbound; m++)
{
if (m = = 1)//If the first page is displayed in this way: 20070524.shtml instead of 20070524_1.shtml
Strnumber = Strnumber + "[" + "<a href=" + ". /"+ Strdate +". sHTML "+" > "+ M +" </a> "+"] ";
Else
{
int n = m-1;//The third page of the connection should be 20070524_2.shtml, etc.
Strnumber = Strnumber + "[" + "<a href=" + ". /"+ Strdate +" _ "+ N +". sHTML "+" > "+ M +" </a> "+"] ";
}
}
if (upbound = 0)//If there is no paging, directly save by date time
{
filepath = Server.MapPath ("http://www.cnblogs.com/") + "Newsfiles" + "//" + Strdate + ". shtml";
strHTML = Strhtml.replace ("pager", "");
}
else//otherwise press 20070524.shtml, 20070524_1.shtml this effect to save
{
if (i = = 0)
filepath = Server.MapPath ("http://www.cnblogs.com/") + "Newsfiles" + "//" + Strdate + ". shtml";
Else
filepath = Server.MapPath ("http://www.cnblogs.com/") + "Newsfiles" + "//" + Strdate + "_" + i + ". shtml";
if (i = = 0)//first page does not show previous page
strtable = Strtable.replace ("Upurl", "");
if (I <= 1)//prev page pagination
strtable = Strtable.replace ("Upurl", "<a href=" + "...) /"+ Strdate +". sHTML "+ > Prev </a>");
Else
{
int p = i-1;
strtable = Strtable.replace ("Upurl", "<a href=" + "...) /"+ Strdate +" _ "+ P +". sHTML "+ > Prev </a>");
}
if (Upbound = 1)//If there is only one page, the page number is not displayed
Strnumber= "";
strtable = Strtable.replace ("number", "");
Else
strtable = Strtable.replace ("number", strnumber);//page replacement
/**/
////////////////////////
if (i = = upbound-1)//The last page does not show the next page
strtable = Strtable.replace ("Downurl", "");
if (i!= upbound-1)//Next page pagination
{
int q = i + 1;
strtable = Strtable.replace ("Downurl", "<a href=" + "...) /"+ Strdate +" _ "+ Q +". sHTML "+ > Next </a>");
}
Else
{
int j = upbound-1;
strtable = Strtable.replace ("Downurl", "<a href=" + "...) /"+ Strdate +" _ "+ j +". sHTML "+ > Next </a>");
}
strHTML = Strhtml.replace ("pager", strtable);
}
Create a file information object--------------------------------------------
FileInfo finfo = new FileInfo (filepath);
Create a file stream in the form of open or write
using (FileStream fs = Finfo.openwrite ())
{
Create a write stream based on the file flow created above
StreamWriter sw = New StreamWriter (FS, System.Text.Encoding.Default);
Write new content to the HTML page you created
Sw.writeline (strhtml);
Sw.flush ();
Sw.close ();
}
}
}
catch (Exception err)
{
Output exception information
Response.Write (Err.tostring ());
}
}
}
}