ASP.NET动态生成静态页面(C#)
来源:互联网 发布:网络机房设备 编辑:程序博客网 时间:2024/05/01 23: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
}
}
{
/// <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
}
}
- ASP.NET动态生成静态页面(C#)
- ASP.NET动态生成静态页面(C#)
- ASP.NET动态生成静态页面(C#)
- ASP.NET 动态生成静态页面
- ASP.NET动态生成静态页面
- asp.net(c#)生成静态html页面
- asp.net(c#)生成静态html页面
- asp.net(c#)生成静态html页面
- C#(asp.net)根据静态模板生成静态(html)页面
- ASP动态生成静态页面
- 在ASP.NET动态页中生成静态页面
- ASP.NET 动态页面生成静态页的方法
- ASP.NET动态生成静态页面的方法
- ASP.NET动态生成静态页面的实例代码
- ASP.NET动态生成静态页面的实例代码
- ASP.NET生成静态页面
- ASP.Net生成静态页面
- ASP.Net生成静态页面
- 系统理解Win32andMFC
- 歌词
- javascript高级属性:私有 和 继承
- 远程调用技术代码追踪(webservice)
- 每天一句(十七)
- ASP.NET动态生成静态页面(C#)
- 应用--设计模式的原则
- 页面自定义拖拽布局
- CSS2.0中最常用的18条技巧
- 设计模式
- 直线的多边形裁剪及任意多边形互裁剪
- GridView自定义分页
- ORA-01779错误的处理方法(转贴:http://tech.inspiremedia.org/archives/82.html,原作者:charlee)
- 技术与生活