[Original] Asp.net static page generation scheme

Source: Internet
Author: User

Static Page generation scheme
News table t_artice
The fields are as follows:
ID: News ID
Title
Content
Date
Author of author
Link HTML corresponds to a static page
// Whether hasupdate is updated

When adding News, a static page is generated and the link address is recorded in the database.
When updating news, delete the static page to which the current news points, generate a new static page, update the link address, and record it in the library.

 

Theme.htm FileCode

<! 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>
<Title> No title page </title>
</Head>
<Body>
<Table>
<Tr>
<TD style = "width: 100px">
User name </TD>
<TD style = "width: 100px"> @ PPT [0] @
</TD>
</Tr>
<Tr>
<TD style = "width: 100px">
IP </TD>
<TD style = "width: 100px"> @ PPT [1] @
</TD>
</Tr>
<Tr>
<TD style = "width: 100px">
Information </TD>
<TD style = "width: 100px"> @ PPT [2] @
</TD>
</Tr>
<Tr>
<TD style = "width: 100px">
Page </TD>
<TD style = "width: 100px"> @ PPT [3] @
</TD>
</Tr>
</Table>

</Body>
</Html>

Writehtml. aspx code

Random Rand = new random ();
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Ads. BLL. t_log blllog = new ads. BLL. t_log ();
Dataset DS = new dataset ();
DS = blllog. getalllist ();
If (Ds! = NULL)
{
Lblmsg. Text = "<Table> ";
Foreach (datarow row in DS. Tables [0]. Rows)
{
String file = write (row ["username"]. tostring (), row ["userip"]. tostring (), row ["page"]. tostring (), row ["message"]. tostring ());
Lblmsg. text + = "<tr> <TD> <a href =" + file + "target = _ blank>" + row ["username"]. tostring () + "</a> ";
}
Lblmsg. Text + = "</table> ";
}
}
}

Private string write (string username, string IP, string page, string MSG)
{
String filesname = "";
String [] format = new string [4]; // defines an array with the same number of htmlyem tags
Stringbuilder htmltext = new stringbuilder ();
Try
{
Using (streamreader sr = new streamreader (server. mappath ("theme.htm ")))
{
String line;
While (line = Sr. Readline ())! = NULL)
{
Htmltext. append (line );
}
Sr. Close ();
}
}
Catch
{
Response. Write ("<SCRIPT> alert (~ File Reading error ~) </SCRIPT> ");
}

Format [0] = username;
Format [1] = IP;
Format [2] = MSG;
Format [3] = page;
For (INT I = 0; I <4; I ++)
{
Htmltext. Replace ("@ PPT [" + I + "] @", format [I]);
}
Try
{

String S = Rand. Next (999999). tostring ();
String filename = datetime. Now. Hour. tostring () + datetime. Now. Minute. tostring () + datetime. Now. Second. tostring () + S + ". htm ";
Filesname = filename;
Filename = server. mappath (filename );
Using (streamwriter Sw = new streamwriter (filename, false, system. Text. encoding. getencoding ("gb2312 ")))
{
Sw. writeline (htmltext );
Sw. Flush ();
Sw. Close ();
}
}
Catch
{
Response. Write ("the file cocould not be wirte :");
}
Return filesname;
}

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.