当前位置: 代码迷 >> ASP.NET >> 生成静态页面有关问题,请大家帮忙看下
  详细解决方案

生成静态页面有关问题,请大家帮忙看下

热度:9248   发布时间:2013-02-25 00:00:00.0
生成静态页面问题,请大家帮忙看下
为什么生成的静态页面是空的,什么内容都没有,连html代码都没,请帮我看看哪有问题,谢了。
这是模板
HTML code
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>{##title##} </title>
<link rel="stylesheet" type="text/css" href="../../css/css.css" />
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
</head>

<body>
<div style="width:1002px; margin:auto;">
<iframe scrolling="no" width="1002px" height="132px" src="../../UserControl/newsheader.aspx" frameborder="0"> </iframe> </div>
<div style="width:1002px; margin:auto;"> <img src="../../images/xwzx_02.gif" /> </div>
<div id="newsshow">
  <div class="news_nr">
      <div style="font-family:'宋体'; font-size:16px; font-weight:bold; color:#FFFFFF; text-align:center">{##title##} </div>
  <div style="font-family:'宋体'; margin-top:6px; margin-bottom:6px; font-size:12px; color:#FFFFFF; text-align:center">{##time##} </div>
    <div style="font-family:'宋体'; margin-top:6px; margin-bottom:6px; font-size:12px; color:#FFFFFF; margin:6px 200px;">{##text##} </div>
  </div>
</div>
<div id="Banquan"> &copy;2007-2008 </div>
</body>
</html>



这是生成静态页的类
C# code
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;using System.Text;/// <summary>/// 生成静态页面类/// </summary>public class StaticHtml{    /// <summary>    /// 新闻标题    /// </summary>    private string _title = "这里是标题的内容";    /// <summary>    /// 新闻内容    /// </summary>    private string _content = "暂无内容";    /// <summary>    /// 新闻上传时间    /// </summary>    private string _time = "";    /// <summary>    /// 生成的文件的保存路径;    /// </summary>    private string _path = "htmlpath";    /// <summary>    /// 返回静态页的地址    /// </summary>    private string _htmlPath;    /// <summary>    /// 返回消息    /// </summary>    private string _msg;    /// <summary>    /// 新闻标题    /// </summary>    public string Title    {        set        {            _title = value;        }        get        {            return _title;        }    }    /// <summary>    /// 新闻内容    /// </summary>    public string Content    {        set        {            _content = value;        }        get        {            return _content;        }    }     /// <summary>    /// 新闻上传时间    /// </summary>    public string Time    {        set        {            _time = value;        }        get        {            return _time;        }    }    /// <summary>    /// 生成的文件的保存路径;    /// </summary>    public string Path    {        set        {            _path = value;        }        get        {            return _path;        }    }    /// <summary>    /// 返回消息    /// </summary>    public string Msg    {        get        {            return _msg;        }    }     /// <summary>    /// 返回静态页的地址    /// </summary>    public string HtmlPath    {        get        {            return _htmlPath;        }    }    public StaticHtml()    {        //        // TODO: 在此处添加构造函数逻辑        //    }    public void GetHtml()     {        //创建静态页文件夹的文件夹名(eg:2008-09)        string _dt = DateTime.Now.ToString("yyyyMM");        //创建静态页文件夹的绝对路径        string _outPutPath = HttpContext.Current.Server.MapPath("~")+"\\" + Path + "\\" + _dt + "\\";        //用于创建,移动,枚举目录的实例        DirectoryInfo directoryinfo = new DirectoryInfo(_outPutPath);        //如果文件夹不存在创建文件夹        if (!directoryinfo.Exists)         {            directoryinfo.Create();        }        //编码格式        Encoding encoding = Encoding.GetEncoding("gb2312");        //静态页母版的绝对路径        string _modelPath = HttpContext.Current.Server.MapPath("Temp/temp");        //声明一个读流        StreamReader sr = null;        //声明一个写流        StreamWriter sw = null;        //声明一个字符串用来替换title,content,time        string _str="";        try        {            //实例化一个读流对象,参数母版绝对路径和编码格式            sr = new StreamReader(_modelPath, encoding);            //从当前位置到末尾把母版读到流里            sr.ReadToEnd();        }        catch (Exception ex)        {            HttpContext.Current.Response.Write(ex.Message);            HttpContext.Current.Response.End();            sr.Close();        }          //生成的静态页的文件名(把-替换成“”)        string _htmlName = DateTime.Now.ToShortDateString().Replace("-","")                           + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()                           + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + "";        _str = _str.Replace("{##title##}", Title);        _str = _str.Replace("{##time##}", Time);        _str = _str.Replace("{##text##}", Content);        try         {            sw = new StreamWriter((_outPutPath + _htmlName),false,encoding);            sw.Write(_str);            sw.Flush();            _msg = " 成功生成静态页面!";            _htmlPath = _dt + "\\" + _htmlName;        }        catch(Exception ex)        {             HttpContext.Current.Response.Write(ex.Message);             HttpContext.Current.Response.End();             _msg = "产生错误,请重试";        }        finally        {            sw.Close();        }           }}
  相关解决方案