asp.net generating static pages and paging

Source: Internet
Author: User
Tags datetime html tags mysql tutorial prev trim

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>

&lt;/font&gt; time


&lt;/div&gt;


&lt;div style= "WIDTH:417PX; height:100px "&gt;


Content


&lt;/div&gt;


&lt;div style= "WIDTH:416PX; Height:9px "&gt;


Pager


&lt;/div&gt;


&lt;div style= "WIDTH:416PX; Height:8px "&gt;


&lt;form id= "Form1" action= ". /addcomment.aspx "style=" margin:0px "&gt;


&lt;input id= "Text1" type= "text"/&gt;


&lt;img id= "Image1" src= "http://www.0379zd.com/userinfo/checkcode.aspx"/&gt;


&lt;br/&gt;


&lt;textarea id= "commentcontent" cols= "rows=" "2" &gt; &lt;/textarea&gt;


&lt;br/&gt;


&lt;input id= "NewSID" type= "hidden" value= "NewSID"/&gt;


&lt;input id= "Button1" type= "Submit" value= "button"/&gt;


&lt;a href= "Http://www.0379zd.com/news/display.aspx?newsid=newsid" &gt; see more reviews &lt;/a&gt;


&lt;/form&gt;


&lt;/div&gt;


&lt;/body&gt;


&lt;/html&gt;


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 "%>

&lt;%@ register tagprefix= "Fckeditorv2" namespace= "Fredck.fckeditorv2" assembly= "Fredck.fckeditorv2"%&gt;


&lt;!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd "&gt;


&lt;html xmlns= "http://www.w3.org/1999/xhtml" &gt;


&lt;head id= "Head1" runat= "Server" &gt;


&lt;title&gt; Add News &lt;/title&gt;


&lt;/head&gt;


&lt;body&gt;


&lt;form id= "Form1" runat= "Server" &gt;


&lt;div&gt;


&lt;asp:label id= "Label2" runat= "Server" text= "title" &gt; &lt;/asp:label&gt;


&lt;asp:textbox id= "title" runat= "Server" width= "325px" &gt; &lt;/asp:textbox&gt;


&lt;br/&gt;


&lt;asp:label id= "Label1" runat= "server" text= "Content" &gt; &lt;/asp:label&gt;


&lt;fckeditorv2:fckeditor id= "Content" basepath= "~/fckeditor/" runat= "Server" height= "400px" width= "70%" &gt;


&lt;/fckeditorv2:fckeditor&gt;


&lt;asp:button id= "button1" runat= "Server" onclick= "Button1_Click" text= "button"/&gt;


&lt;asp:label id= "message" runat= "Server" &gt; &lt;/asp:label&gt;


&lt;/div&gt;


&lt;/form&gt;


&lt;/body&gt;


&lt;/html&gt;


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 &lt; 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 &lt;= upbound; m++)


{


if (m = = 1)//If the first page is displayed in this way: 20070524.shtml instead of 20070524_1.shtml


Strnumber = Strnumber + "[" + "&lt;a href=" + ". /"+ Strdate +". sHTML "+" &gt; "+ M +" &lt;/a&gt; "+"] ";


Else


{


int n = m-1;//The third page of the connection should be 20070524_2.shtml, etc.


Strnumber = Strnumber + "[" + "&lt;a href=" + ". /"+ Strdate +" _ "+ N +". sHTML "+" &gt; "+ M +" &lt;/a&gt; "+"] ";


}


}


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 &lt;= 1)//prev page pagination


strtable = Strtable.replace ("Upurl", "&lt;a href=" + "...) /"+ Strdate +". sHTML "+ &gt; Prev &lt;/a&gt;");


Else


{


int p = i-1;


strtable = Strtable.replace ("Upurl", "&lt;a href=" + "...) /"+ Strdate +" _ "+ P +". sHTML "+ &gt; Prev &lt;/a&gt;");


}

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", "&lt;a href=" + "...) /"+ Strdate +" _ "+ Q +". sHTML "+ &gt; Next &lt;/a&gt;");


}


Else


{


int j = upbound-1;


strtable = Strtable.replace ("Downurl", "&lt;a href=" + "...) /"+ Strdate +" _ "+ j +". sHTML "+ &gt; Next &lt;/a&gt;");


}

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 ());


}


}


}


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.