As an exercise I added "Insert Code" "Insert Run Code", you can see the situation, add other ubb.
2, Code:
Default.aspx.cs
Copy Code code 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)
{
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]", "¤");
tempcontent = content. Split (' ¤ ');
String Pagenav = String. Empty;
for (int j = 0; J < Tempcontent.length; J + +)
{
Pagenav + + "<a href= '" + (j + 1) + ". htm ' >" + (j + 1) + "page </a>";
}
for (int i = 0; i < tempcontent.length; i++)
{
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;
}
}
UBB Replacement
public string UBB (string sdetail)
{
Sdetail = Server.HTMLEncode (Sdetail);
Sdetail = Sdetail.replace ("\ r \ n", "<br/>");
Regex R;
Match m;
Code
R = new Regex (\[code\]) ([\s\s]+?) (\[\/code\]) ", regexoptions.ignorecase);
for (M = R.match (sdetail); m.success m = M.nextmatch ())
{
Sdetail = Sdetail.replace (M.groups[0]. ToString (), "<textarea style=\" border:1px solid #94BBE2; background: #FAFAFA; width:90%;cursor:default;padding:5px ; \ "Rows=\" 15\ ">" + m.groups[2]. ToString (). Replace ("<br/>", "\ n") + "</textarea><br/>");
}
int i = 1;
Html
R = new Regex (\[html\]) ([\s\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= ' Run code ' onclick=\ ' RunCode (' Code "+i+"] \ "/><input type= ' button ' value= ' Copy codes ' onclick=\" Copycode (' Code ' +i+ ') \ "/>");
}
return sdetail;
}
Write a file
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 files
public static string ReadFile (String Path)
{
string s = "";
if (! System.IO.File.Exists (Path))
s = "There is no corresponding directory";
Else
{
StreamReader F2 = new StreamReader (Path, System.Text.Encoding.GetEncoding ("Utf-8"));
s = F2. ReadToEnd ();
F2. Close ();
F2. Dispose ();
}
return s;
}
}
Current 1/2 page 12 Next read the full text