博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET动态生成静态页面(C#)
阅读量:6891 次
发布时间:2019-06-27

本文共 2312 字,大约阅读时间需要 7 分钟。

namespace BankAccount.test{ ///  /// HtmlWriter 的摘要说明。 ///  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 = ""+     "
"+ ""+ title +""; dhtml += "
"+ "
"+ title +"
"+ cription +"
"+ ""; 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("",""); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion }}

 

转载于:https://www.cnblogs.com/wifi/articles/2501923.html

你可能感兴趣的文章
还在傻傻用Ctrl+C和Ctrl+V吗?这2个行列转置方法助你效率提80%!
查看>>
webpack4.0各个击破(5)—— Module篇
查看>>
没有什么内存问题,是一行Python代码解决不了的
查看>>
备忘录模式
查看>>
RabbitMQ之集群搭建
查看>>
进程占用量100%问题定位
查看>>
CentOS安装crontab及使用方法
查看>>
Dockerfile构建容器
查看>>
Shell、Xterm、Gnome-Terminal,Konsole简介
查看>>
iptables小脚本
查看>>
configure.ac:9: error: Autoconf version 2.63 or higher is required
查看>>
为什么TCP存在重传
查看>>
Vbs脚本编程简明教程之三
查看>>
my.cnf配置说明详解(16G内存)
查看>>
7款很棒的 HTML5 视频播放器
查看>>
RHEL5 xmanager配置
查看>>
我的友情链接
查看>>
OSPF学习 DR/BDR选举规则
查看>>
如果说我有一个改变世界的 idea,打算辞职全身心去创业,你们觉得靠谱么
查看>>
JS、Python对字符串的编码函数
查看>>