.net2.0怎么生成静态页面??
请把文件发到
发过来的时候请注明您CSDN里的用户名~~用得上100分送上.

解决方案 »

  1.   

    http://download.csdn.net/source/293578
      

  2.   

    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.Xml;
    using System.Text;/// <summary>
    /// CreatHtml 的摘要说明
    /// </summary>
    public class CreatHtml
    {
        public CreatHtml()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }    //生成HTML页
        public static bool WriteFile(string strText, string strContent, string strAuthor)
        {
            string path = HttpContext.Current.Server.MapPath("news");
            Encoding code = Encoding.GetEncoding("gb2312");
            // 读取模板文件
            string temp = HttpContext.Current.Server.MapPath("newsTemplate/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";
            // 替换内容
            // 这时,模板文件已经读入到名称为str的变量中了
            str = str.Replace("ShowArticle", strText); //模板页中的ShowArticle
            str = str.Replace("biaoti", strText);
            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();
            }
            return true;
        }
    }
      

  3.   

     sr   =   new   StreamReader(temp,   code); 
     str   =   sr.ReadToEnd();   //   读取文件 
     摸板页里面定义那几个标签就可以了。自己试一下嘛
      

  4.   

    aweicd0395 给你发了邮件~~请给我回邮件.马上结分
      

  5.   

    if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString))) 

    Response.Write("添加成功"); 

    else 

    Response.Write("生成HTML出错!"); 

    这个有错误
      

  6.   

    public   static   bool   WriteFile(string   strText,   string   strContent,   string   strAuthor) 
    这里是要传三个什么值过来???
      

  7.   

    看看孟老大滴帖子吧
    在ASP.NET 2.0中直接得到本页面生成的HTML代码不过俺后来又扩展了一下,需两个参数 requestUri 和 staticFilePath,
    这样放到俺滴扩展库里作为通用方法,哈
      

  8.   

    其实我们要静态的是做什么了,就是为了SEO,那么我们还有些内容是要动态怎么办了,所以不能生成静态就是可以,统计啊,相关评论啊都可以用动态的做,这个就叫动静结合吧,看看我的网,查看HTML代码可能有你想要的,www.jobdll.com 新闻栏目,www.jobdll.com/user/gt 这个也是的BLOG
      

  9.   

                    /// <summary>
    /// 生成HTML页
    /// </summary>
    /// <param name="newsID">新闻唯一编号(统计用)</param>
    /// <param name="title">新闻名称</param>
    /// <param name="content">新闻内容</param>
    /// <param name="addTime">发表时间</param>
    /// <param name="filePath">要保存的路径</param>
    /// <param name="stencilPath">模版页路径及文件名称</param>
    /// <returns></returns>
    public static void CreateHtmlFile(string newsID,string title,string addTime,string content,string filePath,string stencilPath)
    {
    string path = System.Web.HttpContext.Current.Server.MapPath(filePath);
    Encoding code = Encoding.GetEncoding("gb2312");
    System.IO.DirectoryInfo dir=new System.IO.DirectoryInfo(path.Substring(0,path.LastIndexOf("\\")));
    //判断文件夹否存在,不存在则创建
    if(!dir.Exists)
    {
    dir.Create();
    }
    // 读取模板文件
    string temp = System.Web.HttpContext.Current.Server.MapPath(stencilPath);
    StreamReader sr=null;
    StreamWriter sw=null;
    string str=""; 
    try
    {
    sr = new StreamReader(temp, code);
    str = sr.ReadToEnd(); // 读取文件
    sr.Close();
    }
    catch(Exception exp)
    {
    System.Web.HttpContext.Current.Response.Write(exp.Message);
    System.Web.HttpContext.Current.Response.End();
    sr.Close();
    }
    //string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".htm"; // 替换模版中的内容
    str = str.Replace("[newsid]",newsID); //替换新闻ID
    str = str.Replace("[title]",title); //替换新闻标题
    str = str.Replace("[addtime]",addTime); //替换新闻更新时间
    str = str.Replace("[content]",content); //替换新闻内容
    // 写文件
    try
    {
    sw = new StreamWriter(path, false, code);
    sw.Write(str);
    sw.Flush();
    }
    catch(Exception ex)
    {
    System.Web.HttpContext.Current.Response.Write(ex.Message);
    System.Web.HttpContext.Current.Response.End();
    }
    finally
    {
    sw.Close();
    }
    }楼主还不明白就加我Q82161001
      

  10.   

    http://blog.csdn.net/Samanthaqu/archive/2007/12/04/1915881.aspx其中:
    string fileName = Request.Form["ddlDate"] + ".htm";
    Response.WriteFile(Server.MapPath("~/ProjectHome/Upload/" + fileName));
    Response.End();