用 aspx(C#) 发布的新闻,如何能按 年月日 的目录 生成静态 html 页呢?求一个完美些的解决方案!多谢各位高人帮忙!

解决方案 »

  1.   

    这是一个ASPX页面动态转静态的问题,我所知的有两种方法.
    方法1:使用模板转换.
    方法2: 重写AttributeCollection.Render
    请参考一个地方:
    http://www.cnblogs.com/smh188/archive/2007/07/13/817735.html
      

  2.   

    完美??完美即是不存在。
    给你一个不能算是完美的文章。
    将Asp.net页面输出为HTML     
    http://blog.csdn.net/octverve/archive/2007/09/04/1771107.aspx
    自己再灵活的改一下。应该是适合你说的
      

  3.   

    http://topic.csdn.net/t/20051127/12/4420997.html
      

  4.   

    首先要有个摸板html页,如下
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <HTML>
     <HEAD>
     <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
      <title>$ShowArticle$</title>
      </HEAD>
     <body>
     标题:$biaoti$
     <br/>
     内容开始<br/><br/>
     $content$<br/>
     <br/><br/>作者:$author$
     <br/>结束
     </body>
    </HTML>
      

  5.   

    然后是CS代码,如下
        protected void LoadStaticPage(string strText, string Biaoti, string strContent, string strAuthor)
        {
            string path = HttpContext.Current.Server.MapPath("FilePath/");
            Encoding code = Encoding.GetEncoding("gb2312");
            // 读取模板文件
            string temp = HttpContext.Current.Server.MapPath("FilePath/Text.html");
            StreamReader sr = null;
            StreamWriter sw = null;
            string str = "";
            try
            {
                sr = new StreamReader(temp, code);
                str = sr.ReadToEnd(); // 读取文件
            }
            catch (Exception exp)
            {
                HttpContext.Current.Response.Write(exp.Message);
                HttpContext.Current.Response.End();
                sr.Close();
            }        //string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
            string htmlfilename = "Text1.html";
            // 替换内容
            // 这时,模板文件已经读入到名称为str的变量中了
            str = str.Replace("$ShowArticle$", strText); //模板页中的ShowArticle
            str = str.Replace("$biaoti$", Biaoti);
            str = str.Replace("$content$", strContent);
            str = str.Replace("$author$", strAuthor);
            // 写文件
            try
            {
                sw = new StreamWriter(path + htmlfilename, false, code);
                sw.Write(str);
                sw.Flush();
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.Message);
                HttpContext.Current.Response.End();
            }
            finally
            {
                sw.Close();
            }
            Response.Redirect("FilePath/Text1.html");
        }
      

  6.   

    LoadStaticPage里的参数,根据你的需要在HTML页中显示的传入。
    最后重新生成一个新的HTML页,我给出了根据年月日定义页面的代码段。
    你参考一下
      

  7.   

    先根据文章的日期获取年/月/日的目录名字。判断年月日目录是否存在。不存在创建他们。在日目录中生成html文件不知道lz想要的完美方案是什么?