int num = 0;
String sql = INSERT INTO news (Title,content,bigclassname,[user],infotime,hits,upfile) VALUES (@title, @content, @ddl, @ Name, @time, @num, @filename) ";
Oledbparameter[] para = new oledbparameter[] {
New OleDbParameter ("@title", Txttitle.text),
New OleDbParameter ("@content", Fckeditor1.value),
New OleDbParameter ("@ddl", Ddllei.selecteditem.value),
New OleDbParameter ("@name", txtName.Text),
New OleDbParameter ("@time", Txttime.text),
New OleDbParameter ("@num", num),
New OleDbParameter ("@filename", filename)
};
Db.executecommand (SQL, para);
String mbpath = Server.MapPath (".. /template/news.html ");
Encoding code = encoding.getencoding ("gb2312");
StreamReader sr = null;
StreamWriter sw = null;
string str = NULL;
Read
Try
{
sr = new StreamReader (Mbpath, code);
str = Sr.readtoend ();
}
catch (Exception ex)
{
throw ex;
}
finally
{
Sr.close ();
}
String Strmax = "SELECT ID from News ORDER by id DESC";
int newsid = Convert.ToInt32 (Db.readout2 (Strmax)) +1;
//automatic renaming based on time, extension can also be modified by itself
string filename = "News_" + NewSID + ". shtml";
str = str.replace ("#title #", Txttitle.text);
str = str.replace ("#infotime #", Txttime.text);
str = str.replace ("#content #", Fckeditor1.value);
Generating static files
Try
{
SW = New StreamWriter (Server.MapPath ("http://www.cnblogs.com/") + filename, false, code);
Sw.write (str);
Sw.flush ();
Fenye ();
}
catch (Exception ex)
{
Throw ex;
}
Finally
{
Sw.close ();
}
Response.Write ("<script language= page Special effects >alert (' Add success! '); location.href= ' newsmanage.asp tutorial x ';</script> ');
Paging
public void Fenye ()
{
string str = "SELECT * from news ORDER by id DESC";
DataTable TB = Db.mydataadapter (str);
DataRow Dr;
//Last page full page
int m = 0;
//pages
int pg = 0;
& nbsp; if (tb.rows.count% = 0)
{
pg = TB.ROWS.COUNT/10;
}
Else
{
pg = Convert.ToInt32 (TB.ROWS.COUNT/10) + 1;
m = 1;
}
Paging
String pglist = "";
for (int i = 1; I <= pg; i++)
{
PGList + + "<a href=" "+ i +". html ">" + i + "</a>";
}
PGList = "<div > Total" +pg+ "page <a href=" 1.html "> Home </a>" + pglist + "<a href=" "+ PG +". html ">& amp;nbsp; end </a></div> ";
for (int j = 1; J <= pg; J +)
{
Create a StringBuilder object
StringBuilder sb = new StringBuilder ();
Reading templates
using (StreamReader sr = new StreamReader (Server.MapPath) (". /template/index.html "), System.Text.Encoding.Default, True)
{
Write template to Streambuilder
Sb.append (Sr.readtoend (). ToString ());
}
Delete an existing file
File.delete (".. /....//news/"+ j.tostring () +". html ");
string title = "";
String ublist = "";
String infotime = "";
String id = "";
if (m = = 1 && j = PG)//Not whole page
{
for (int i = 1 + * (j-1); I <= (tb.rows.count-10 * (pg-1)); i++)
for (int i = 1 + ten * (j-1); I <= (tb.rows.count); i++)
{
Dr = Tb.rows[i-1];
title = dr["title"].tostring ();
id = dr["id"].tostring ();
Infotime = dr["Infotime"].tostring ();
Ublist + + "<table border=" 0 "cellpadding=" 0 "cellspacing=" 0 "style=" width:610px; line-height:10px ">";
Ublist + + <tr ><td align= "left" > "+i+" <a href= "News/news_" + ID + "shtml" >→ "+ title +" </a> &L T;/TD><TD align= "Right" > "+ infotime + </td></tr></table>";
}
}
else//is full page
{
for (int i = 1 + * (j-1); I <= J; i++)
{
Dr = Tb.rows[i-1];
id = dr["id"].tostring ();
title = dr["title"].tostring (). Replace ("", "");
Infotime = dr["Infotime"].tostring (). Replace ("", "");
Ublist + + "<table border=" 0 "cellpadding=" 0 "cellspacing=" 0 "style=" width:610px; line-height:25px ">";
Ublist + = "<tr ><td align=" left ">" + i + "<a href=" News/news_ "+ ID +". shtml ">→" + title + "</a> ; </TD><TD align= "Right" > "+ infotime + </td></tr></table>";
}
}
Replace the contents of the template ...
Sb.replace ("$title $", ublist);
Replace paging
Sb.replace ("$pglist $", pglist);
using (StreamWriter sw = new StreamWriter (Server.MapPath ("http://www.cnblogs.com/news/" + j.tostring () + ". html"), False , System.Text.Encoding.Default, 100))
{
Write an. html file
Sw.writeline (SB);
Sw.flush ();
Sw.close ();
}
}
}
One-click to generate a static page
protected void Btnhtml_click (object sender, EventArgs e)
{
String sql = "SELECT * from news ORDER by id DESC";
DataTable dt = db.mydataadapter (SQL);
if (Dt.rows.count > 0)
{
for (int i = 0; i < Dt.rows.count; i++)
{
String mbpath = Server.MapPath (".. /template/news.html ");
Encoding code = encoding.getencoding ("gb2312");
StreamReader sr = null;
StreamWriter sw = null;
string str = NULL;
Read
Try
{
sr = new StreamReader (Mbpath, code);
str = Sr.readtoend ();
}
catch (Exception ex)
{
Throw ex;
}
Finally
{
Sr.close ();
}
Automatically renamed according to time, extension can also be modified by itself
string filename = "News_" + dt.rows[i]["id"].tostring () + ". sHTML";
str = str.replace ("#title #", dt.rows[i]["title"].tostring ());
str = str.replace ("#infotime #", dt.rows[i]["Infotime"].tostring ());
str = str.replace ("#content #", dt.rows[i]["Content"].tostring ());
Generating static files
Try
{
SW = New StreamWriter (Server.MapPath ("http://www.cnblogs.com/" + "News" + "/") + filename, false, code);
Sw.write (str);
Sw.flush ();
This.page.clientscript.registerstartups Tutorial Cript (GetType (), "", "<script>alert (' Build success! ') </script> ");
}
catch (Exception ex)
{
Throw ex;
}
Finally
{
Sw.close ();
}
}
}
Else
{
This.page.clientscript.registerstartupscript (GetType (), "", "<script>alert (' temporary no data ') </script>");
}
}