怎样把生成的静态页面的文件名称保存在数据库中?
程序的代码如下:
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.HtmlControls;
using System.Data.SqlClient;  //添加引用
using System.Text;
using System.IO;
using System.Collections;
namespace staticeindex
{
/// <summary>
/// media 的摘要说明。
/// </summary>
public class media : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnshengcheng;
protected System.Web.UI.WebControls.ListBox ListBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.btnshengcheng.Click += new System.EventHandler(this.btnshengcheng_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnshengcheng_Click(object sender, System.EventArgs e)
{
string ConStr = "Server=(local);DataBase=ad_class;Uid=sa;Pwd=";
string prostr="select ID from Province_manager ";
SqlConnection Con = new SqlConnection(ConStr);
Con.Open();
SqlCommand Cmd1 = new SqlCommand(prostr,Con);
SqlDataReader dr1 = Cmd1.ExecuteReader();
Hashtable hs = new Hashtable();
if(dr1.HasRows)
{
while(dr1.Read())
{
hs.Add(dr1["ID"].ToString(),dr1["ID"].ToString());                                                                        
}
}
dr1.Close();
Cmd1.Dispose();
foreach(DictionaryEntry de in hs)
{
string strsql="select * from Province_manager join media_info on Province_manager.ID= media_info.Parent_province_id where Province_manager.ID= '"+de.Key.ToString()+"'";
SqlCommand Cmd = new SqlCommand(strsql,Con);
DataSet ds=new DataSet();
SqlDataReader dr = Cmd.ExecuteReader(); 
StringBuilder sb = new StringBuilder();
while(dr.Read())
{
sb.Append("<a href=#>"+dr["Key_index"].ToString()+"</a>"+"&nbsp;&nbsp;");
sb.Append("&nbsp;");
}
WriteFile(sb.ToString());
dr.Close();
}
Response.Write("<script>alert('静态页面生成成功!');location='media.aspx'</script>"); }


public bool WriteFile(string Key_index)
{
string OutPutPath = HttpContext.Current.Server.MapPath("province/city/media/");
Encoding encoding = Encoding.GetEncoding("gb2312");
// 读取模板文件
string ModelTemp = HttpContext.Current.Server.MapPath("ModelHTML.htm");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(ModelTemp, encoding);
str = sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
} Random rd = new Random(unchecked((int)DateTime.Now.Ticks));
string HtmlFilename = rd.Next().ToString()+".html";
// 替换内容
str = str.Replace("ArticleContent", Key_index);

// 写文件
try
{
sw = new StreamWriter(OutPutPath+HtmlFilename, false, encoding);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}

return true;

}
}
}
还请各位大侠帮帮忙,该怎样来写?

解决方案 »

  1.   

    WriteFile(sb.ToString());
    你不是已经生成文件了吗,直接写一个sql: insert into table value ......
    然后ExecuteNoQuery不久完了??
      

  2.   

    只要是能得到这个值,并且数据库中有这个字段,直接insert不就ok了么?
      

  3.   

    niitnanfeng() ( ) 信誉:100    Blog   加为好友  2007-07-02 17:14:37  得分: 0  
     
     
       各位写下,看看该写到哪儿合适,大家仔细点看。没想象的那么简单,有点繁杂!
      
     
    ----------------------------------------------------------------------------
    生成完一个文件后直接写入数据库!