国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET動態生成靜態頁面(C#)

2024-07-10 13:07:28
字體:
來源:轉載
供稿:網友

namespace bankaccount.test
{
 /// <summary>
 /// htmlwriter 的摘要說明。
 /// </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 = "這是動態生成的靜態頁面";
    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";//動態的文件名
    string filepath = server.mappath(@"/bankaccount/test/");
    string cname = datetime.now.year.tostring() + datetime.now.month.tostring();
    string filecreatepath = filepath + cname + @"/";//頁面要保存的路徑

    //動態生成的靜態頁面按年月保存本年本月的文件夾中
    if (directory.exists(filecreatepath)) //判斷當月的文件夾是否存在,
    {
     //調用創建html靜態頁面方法
     create_html(filecreatepath+filename,dhtml);
    }
    else
    {
     //創建頁面保存到的文件夾
     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代碼寫入頁面中
   sw.close();
   page.registerstartupscript("","<script>window.alert('the file created successfully.!')</script>");
  }

  #region web 窗體設計器生成的代碼
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 該調用是 asp.net web 窗體設計器所必需的。
   //
   initializecomponent();
   base.oninit(e);
  }
 
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void initializecomponent()
  {   
   this.load += new system.eventhandler(this.page_load);

  }
  #endregion
 }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜春市| 鄂温| 梁河县| 集贤县| 五大连池市| 郁南县| 利川市| 和硕县| 南汇区| 紫金县| 旺苍县| 嘉黎县| 米林县| 会泽县| 营口市| 永泰县| 界首市| 诸城市| 金昌市| 双牌县| 抚松县| 明水县| 荣昌县| 万年县| 乌什县| 桃源县| 高邑县| 东宁县| 漠河县| 饶河县| 天峻县| 和静县| 镇平县| 聊城市| 泰兴市| 尚义县| 寻乌县| 鄂温| 黄骅市| 抚顺市| 三明市|