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;
}
}