日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

ASP.NET動(dòng)態(tài)生成靜態(tài)頁(yè)面(C#)

 悟靜 2010-10-14

namespace BankAccount.test
{
/// <summary>
/// HtmlWriter 的摘要說(shuō)明。
/// </summary>

public class HtmlWriter : System.Web.UI.Page
{
   private System.Data.SqlClient.SqlDataAdapter myAdapter;
   private System.Data.SqlClient.SqlConnection myConn;
   private System.Data.DataTable myDt;
   private string strConn = ConfigurationSettings.AppSettings["cns"];

   private void Page_Load(object sender, System.EventArgs e)
   {
    try
    {
     string Sqlstr = "Select Cmp_description from Company where Cmp_number = '123567'";
     string cription="";
     myDt = new DataTable();
     myConn = new SqlConnection(strConn);
     myConn.Open();
     myAdapter = new SqlDataAdapter(Sqlstr,myConn);
     myAdapter.Fill(myDt);
     if(myDt.Rows.Count>0)
     {
      cription = myDt.Rows[0]["Cmp_description"].ToString();
     }
     string title = "這是動(dòng)態(tài)生成的靜態(tài)頁(yè)面";
     string dhtml = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//CN\"><html><head>"+
      "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"+
      "<title>"+ title +"</title></head><body topmargin=0>";
     dhtml += "<table width=760 valign=top border=1 cellspacing=1 cellpadding=0 align=center>"+
      "<tr><td height=5>"+ title   +"</td></tr><tr><td height=200 align=center>"+ cription +"</td></tr></table>"+
      "</body></html>";
     string Filename = DateTime.Now.ToString("yyyyMMddHHmmss")+".html";//動(dòng)態(tài)的文件名
     string Filepath = Server.MapPath(@"\BankAccount\test\");
     string Cname = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
     string Filecreatepath = Filepath + Cname + @"\";//頁(yè)面要保存的路徑

     //動(dòng)態(tài)生成的靜態(tài)頁(yè)面按年月保存本年本月的文件夾中
     if (Directory.Exists(Filecreatepath)) //判斷當(dāng)月的文件夾是否存在,
     {
      //調(diào)用創(chuàng)建html靜態(tài)頁(yè)面方法
      Create_html(Filecreatepath+Filename,dhtml);
     }
     else
     {
      //創(chuàng)建頁(yè)面保存到的文件夾
      DirectoryInfo di = Directory.CreateDirectory(Filecreatepath);
      Create_html(Filecreatepath+Filename,dhtml);
     }
    }
    catch(IOException ex)
    {
     throw ex;
    }
   }
   private void Create_html(string allfilename,string htmlcode)
   {
    FileStream CreateFile = new FileStream(allfilename,FileMode.CreateNew);
    StreamWriter sw = new StreamWriter(CreateFile);
    sw.WriteLine(htmlcode);//將拼好的Html代碼寫入頁(yè)面中
    sw.Close();
    Page.RegisterStartupScript("","<script>window.alert('The file created successfully.!')</script>");
   }

   #region Web 窗體設(shè)計(jì)器生成的代碼
   override protected void OnInit(EventArgs e)
   {
    //
    // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
   }
  
   /// <summary>
   /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
   /// 此方法的內(nèi)容。
   /// </summary>
   private void InitializeComponent()
   {    
    this.Load += new System.EventHandler(this.Page_Load);

   }
   #endregion
}
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多