日期:2008-09-26 浏览次数:20524 次
在网上看了许多能生成静态页的新闻系统,但基于asp.net的系统极少,闲下时间来自己写了一个,发出来,大家一起研究,代码没做什么优化,只是实现了功能
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace makehtmlfile
{
/// <summary>
/// makeallfiles 的摘要说明。
/// </summary>
public class makeallfiles : System.Web.UI.Page
{
public string strcon;
public OleDbConnection conn;
public string strSQL;
private void Page_Load(object sender, System.EventArgs e)
{
InitialPages();// 在此处放置用户代码以初始化页面
}
public void InitialPages()
{
strcon = "provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath(ConfigurationSettings.AppSettings["MDBpath2"])+";";//连接字符窜// 在此处放置用户代码以初始化页面
strSQL = "select id,class1id,class2id from news order by id desc";
MakeAreaForShow();
ReadNewsForWriteFileUserDataReader(); //同过DataReader来读取数据,
//ReadNewsForWriteFileUserDataSet(); //将数据直接挂入DataSet中来读取,
}
/// <summary>
/// 用来产生循环显示页面的区域,装载生成HTML页的ASPX页面的区域
/// </summary>
public void MakeAreaForShow()
{
Response.Write("<span id=showImport></span>");
Response.Write("<IE:Download ID='oDownload' STYLE='behavior:url(#default#download)'/>");
}
/// <summary>
/// 通过DATAREADER来读取数据
/// </summary>
public void ReadNewsForWriteFileUserDataReader()
{
int num = 0 ;
string newsid = null;
string class1id = null;
string class2id = null;
OleDbDataReader dr = null;
OleDbConnection conn = new OleDbConnection(strcon);
conn.Open();
OleDbCommand mycommand = new OleDbCommand(strSQL,conn);
dr = mycommand.ExecuteReader();
while(dr.Read())
{
newsid = dr["id"].ToString();
class1id = dr["class1id"].ToString();
class2id = dr["class2id"].ToSt