C # method for generating static pages

Source: Internet
Author: User

C # method for generating static pages: C # method for generating static pages private bool CreateHl (string strtext, string strcontent, string author) {string yearstring = DateTime. now. year. toString (); string monthstring = DateTime. now. month. toString (); string daystring = DateTime. now. day. toString (); string filename = yearstring + monthstring + daystring + DateTime. now. millisecond. toString () + ". html "; Directory. createDirectory (Server. mapPath ("" + years Tring + "//" + monthstring + "//" + daystring + ""); Encoding code = Encoding. getEncoding ("gb2312"); string temp = Server. mapPath ("test.htm"); Response. write (temp); // Response. end (); StreamReader sr = null; StreamWriter sw = null; string str = ""; try {sr = new StreamReader (temp, code); str = sr. readToEnd ();} catch (Exception exp) {Response. write (exp. message); Response. end (); sr. close ();} strcontent + = strconte Nt. replace ("\ n", "<br>"); strcontent + = strcontent. replace ("\ r", "<br>"); str = str. replace ("{pagetitle}", strtext); str = str. replace ("{title}", strtext); str = str. replace ("{content}", strcontent); str = str. replace ("{author}", author); try {// sw = new StreamWriter (str, code); // sw. writeLinesw = new StreamWriter (Server. mapPath ("" + yearstring + "//" + monthstring + "//" + daystring + "//" + filename + ""), False, code); // sw. write; sw. write (str); sw. flush ();} catch (Exception exp) {HttpContext. current. response. write (exp); HttpContext. current. response. end ();} finally {sw. close ();} msg. text = filename; return true;} use protected void Button2_Click (object sender, EventArgs e) {string title = txttitle. text; string content = txtcontent. text; string zuozhe = txtzuzhe. text; bool SC; SC = CreateHl (title, content, zuo Zhe); if (SC) {Response. Write ("HTML generated successfully! ");} Else {Response. Write (" HTML generation failed! ");}}

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.