asp.net与网页模版的结合(转贴)

用asp.net根据网页模版生成自己喜爱的网页

第一部在d盘新建一个HtmModel.htm

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<table $htmlformat[0] height="100%" border="0" width="100%" cellpadding="10" cellspacing="0" bgcolor="#eeeeee" style="border:1px solid #000000">
<tr>
<td width="100%" valign="middle" align="left">
<span style="color: $htmlformat[1];font-size: $htmlformat[2]">$htmlformat[3]</span>
我的网页
</td>
</tr>
</table>
</body>
</html>

在d:盘新建一个用于显示的HtmSee.htm右击HtmSee.htm属性>安全>添加,将asp.net帐户加入文件用户。同时使他有写的权限

清空htmlsee.htm里面的所有html代码

使他成为空的页面

关键

新建一个.net项目然后新建一个页面Make.aspx

Make.aspx.cs代码如下

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;

namespace Study
{
 /// <summary>
 /// produce 的摘要说明。
 /// </summary>
 public class Make : System.Web.UI.Page
 {
  private void Page_Load(object sender, System.EventArgs e)
  {
   string[] format=new string[4];//定义和htmlyem标记数目一致的数组
   StringBuilder htmltext=new StringBuilder(); 
      try
      {
 
             using(StreamReader sr= new StreamReader("D:/HTMLModel.htm"))
            {
            String line;
            while ((line = sr.ReadLine()) != null)
            {
             htmltext.Append(line);
             }
            sr.Close();
            }
   }
      catch
      {
            Response.Write("<Script>alert('读取文件错误')</Script>");
   }

   //---------------------给标记数组赋值------------

   format[0]="background='b7.jpg'";//背景图片
   format[1]= "#990099";//字体颜色
   format[2]="150px";//字体大小
   format[3]= "<marquee>生成的模板html页面</marquee>";//文字说明
   //----------替换htm里的标记为你想加的内容
   for(int i=0;i<4;i++)
   {
              htmltext.Replace("$htmlformat["+i+"]",format[i]);
   }

   //----------生成htm文件------------------――

   try
   {
  using(StreamWriter sw=new    StreamWriter ("D:/HTMLSee.htm",false,System.Text.Encoding.GetEncoding("GB2312")))                           
    {
           
       sw.WriteLine(htmltext);
     sw.Flush();
     sw.Close();
    
    }
   }

     catch
   {

    Response.Write ("The file could not be wirte:");

   
   }
  }

  #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
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值