在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<!—CreateHTML.aspx.cs --> using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; 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.IO; using System.Text;
public partial class CreateHTML : System.Web.UI.Page { public string title = "", content = "", datetime = "", desc = "", pages = "", nowPosition = "", positionlist = null, forindex = "";
protected void Page_Load(object sender, EventArgs e) {
}
//获取文章内容 private void GetArticle(string articles_id) { SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=city;database=test;"); string sql = "select * from articles where articles_id=" + articles_id; SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { nowPosition = this.GetPosition(sdr["articlesgroup_parent_id"].ToString(), positionlist); title = sdr["title"].ToString(); content = Server.HtmlDecode(sdr["article"].ToString()); desc = sdr["articledescription"].ToString(); datetime = sdr["articledatetime"].ToString(); forindex += "<a href='article" + articles_id + ".html'>" + sdr["title"] + "</a><br />"; } else { title = ""; content = ""; desc = ""; datetime = ""; } conn.Close(); }
//创建文章HTML页 private void Createhtml(string article_id) { this.GetArticle(article_id); if (title != "" && content != "") {//防止生成空数据的页面 string[] format = new string[5];//定义和htmlyem标记数目一致的数组 StringBuilder htmltext = new StringBuilder(); try { using (StreamReader sr = new StreamReader(Server.MapPath("temp.htm"))) { String line; while ((line = sr.ReadLine()) != null) { htmltext.Append(line); } sr.Close(); } } catch { Response.Write("<Script>alert('读取文件错误')</Script>"); } |
请发表评论