asp.net 2.0 dynamically generating static pages and paging instances

Source: Internet
Author: User
Tags httpcontext

Look at a lot of pages of the news is paging, I want to implement such a function to see their implementation of the method, basically a news into a number of HTML files saved, and then connected with the page number. (Do not know my understanding is correct, if not correct, please give me the advice twos)

1, from the database to obtain news content. Including news headlines, content and so on.

2, set the length of the string displayed on the page, get the character length of the news content. Do the initial setup

3, according to the length of the page to intercept the character of the news content.

4, get the template page. Replaces a string with a caption, content, and so on in the relevant substitution character.

5, save the new page to the development directory below

Here is the code and resource Manager content,

Solid.aspx Content

 using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using Syste
m.web.security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

Using System.IO; Public partial class Solid:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {W Ritefile ("Olympic theme", "Olympic Games is awesome!")
    
"," 2 "," 2.html "); public void WriteFile (string strText, string content, String page, string name) {String path = Httpcont Ext. Current.Server.MapPath ("News/get"); System.Text.Encoding code = System.Text.Encoding.GetEncoding ("gb2312"); Read template file String temp = HttpContext.Current.Server.MapPath ("news/text.htm"); StreamReader sr = null; StreamWriter sw = null; String str = ""; try {sr = new StreamReader (temp, code); str = Sr. ReadToEnd (); Reading files The catch (Exception exp) {HttpContext.Current.Response.Write (exp. message); HttpContext.Current.Response.End (); Sr. Close (); String htmlfilename = name. ToString (); Replace///At this time, the template file has been read into the variable named str = str. Replace ("$title", StrText); $title in the template page, that is, title str = str. Replace ("$content", content);//$content in the template page, that is, contents str = str. Replace ($page, page),//$page in the template page, that is, page number connection format/write file try {sw = new StreamWriter (path + "/" + Htmlfilename, False, code); Sw. Write (str); Sw. Flush (); The catch (Exception ex) {HttpContext.Current.Response.Write (ex). message); HttpContext.Current.Response.End (); finally {SW. Close (); } } }

Text.htm Content

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<title>无标题页</title>
<body>
<div style="font-size: 20px; text-align: center;">文章分页测试</div>
<div style="font-size: 15px; text-align: center; color: #009966;">$title</div>
<div style="font-size: 12px; text-align: center; color: darkgray;">$page</div>
<div style="font-size: 12px;">$content</div>
</body>

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.