• 转静态方法示例


    < DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>

    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>
    /// CreateHtml 的摘要说明
    /// </summary>
    public class CreateHtml
    {
         public CreateHtml()
         {
             //
             // TODO: 在此处添加构造函数逻辑
             //
         }
         public bool CreateHtm(string strText, string strContent, string strAuthor)
         {
             string yearString = DateTime.Now.Year.ToString();
             string monthString = DateTime.Now.Month.ToString();
             string dayString = DateTime.Now.Day.ToString();

             string fileName = yearString + monthString + dayString + DateTime.Now.Millisecond.ToString() + ".html";
             Directory.CreateDirectory(HttpContext.Current.Server.MapPath("" + yearString + "//" + monthString + "//" + dayString + ""));

             Encoding code = Encoding.GetEncoding("utf-8");
             string temp = HttpContext.Current.Server.MapPath("HTMLPage.htm");
             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();
             }
             //替换
             str = str.Replace("ShowArticle", strText);
             str = str.Replace("biaoti", strText);
             str = str.Replace("content", strContent);
             str = str.Replace("author", strAuthor);

             try
             {

                 sw = new StreamWriter(HttpContext.Current.Server.MapPath("" + yearString + "//" + monthString + "//" + dayString + "//" + fileName + ""), false, code);
                 sw.Write(str);
                 sw.Flush();
             }
             catch (Exception exp)
             {
                 HttpContext.Current.Response.Write(exp.Message);
                 HttpContext.Current.Response.End();
             }
             finally
             {
                 sw.Close();
             }
             return true;
         }

    }

  • 相关阅读:
    很老的一篇文章:李翱(伊秀女性网):从程序员到精英站长的跨度
    推荐一款很好用的CSS下拉菜单框架
    网站推广之软文写作与发布技巧
    SEO网站外链接分析工具
    图解几大浏览器的区别(搞笑)
    好文摘抄:极简生活:一来,一去
    南通搜索引擎优化:浅谈国内SEO的发展趋势
    关注程序员健康之——程序员最有效的十大戒烟方法
    [你必须知道的css系列]第一回:丰富的利器:CSS选择符之通配符、类选择符、包含选择符、ID选择符
    [你必须知道的css系列]第一回:冠冕堂皇:CSS的作用及其基本结构
  • 原文地址:https://www.cnblogs.com/netcorner/p/2912331.html
Copyright © 2020-2023  润新知