Asp.net generates static pages and pages + UBB page 1/2

Source: Internet
Author: User


As an exercise, I added "insertCode"Insert the Running code". You can check the situation and add it to other UBB instances.

2. Code:
Default. aspx. CS

Copy code The Code is as follows: using system;
Using system. Data;
Using system. configuration;
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 system. Text. regularexpressions;
Using system. IO;

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}

protected void btnok_click (Object sender, eventargs e)
{< br> string Path = server. mappath ("~ /Template/news.htm ");
string topath = server. mappath ("~ /News/");
string [] tempcontent = new string [] {};
string S1 = readfile (PATH);
String title = This. tbxtitle. text;
string content = UBB (this. tbxcontent. text);
string S3 = string. empty;
content = content. replace ("[Page]", "updated");
tempcontent = content. split ('signature');
string pagenav = string. empty;
for (Int J = 0; j {< br> pagenav + = " page "+ (J + 1) +" ";
}< br> for (INT I = 0; I {< br> S3 = s1.replace ("$ title $", title);
S3 = s3.replace ("$ content $ ", tempcontent [I]. tostring ();
S3 = s3.replace ("$ pagelist $", pagenav);
writefile (topath + (I + 1) + ". htm ", S3);
S3 = string. empty;
}< BR >}

// replace UBB
Public String UBB (string sdetail)
{< br> sdetail = server. htmlencode (sdetail);
sdetail = sdetail. replace ("\ r \ n", "
");
RegEx R;
Match m;
// Code
r = new RegEx (@ "(\ [Code \]) ([\ s] + ?) (\ [\/Code \]) ", regexoptions. ignorecase);
for (M = R. match (sdetail); M. success; M = m. nextmatch ()
{< br> sdetail = sdetail. replace (M. groups [0]. tostring (), "" + M. groups [2]. tostring (). replace ("<br/>", "\ n") + "
");
}

Int I = 1;
// Html
R = new RegEx (@ "(\ [HTML \]) ([\ s] + ?) (\ [\/Html \]) ", regexoptions. ignorecase );
For (M = R. Match (sdetail); M. success; M = M. nextmatch ())
{
I = I + 1;
Sdetail = sdetail. replace (M. groups [0]. tostring (), "<textarea rows = \" 12 \ "style = \" width: 90% \ "id = \" code "+ I +" \ ">" + M. groups [2]. tostring (). replace ("<br/>", "\ n ") + "</textarea> <br/> <input type = 'button 'value = 'running Code' onclick = \" runcode ('Code "+ I + "') \ "/> <input type = 'button 'value = 'Copy code 'onclick = \" copycode ('Code "+ I +"') \ "/> ");
}
Return sdetail;
}

// Write an object
Public static void writefile (string path, string strings)
{
If (! System. Io. file. exists (PATH ))
{
System. Io. filestream F = system. Io. file. Create (PATH );
F. Close ();
}
System. Io. streamwriter F2 = new system. Io. streamwriter (path, false, system. Text. encoding. getencoding ("UTF-8 "));
F2.write (strings );
F2.close ();
F2.dispose ();
}

// Read the file
Public static string readfile (string path)
{
String S = "";
If (! System. Io. file. exists (PATH ))
S = "the corresponding directory does not exist ";
Else
{
Streamreader F2 = new streamreader (path, system. Text. encoding. getencoding ("UTF-8 "));
S = f2.readtoend ();
F2.close ();
F2.dispose ();
}
Return S;
}

}

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.