zoukankan      html  css  js  c++  java
  • 转静态方法示例

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

    }

  • 相关阅读:
    Vue-ui常用组件库整理
    给博客添加fork me on github图标
    element-ui 带单选框的表格
    css grid 网格布局
    TensorFlow学习笔记(6):TensorBoard之Embeddings
    ES6 异步编程之一:Generator
    浅析 Node.js 的 vm 模块以及运行不信任代码
    使用 D8 分析 javascript 如何被 V8 引擎优化的
    深入新版BS4源码 探索flex和工程化sass奥秘
    PHP-7.1 源代码学习:字节码生成 之 "$a = 1"
  • 原文地址:https://www.cnblogs.com/netcorner/p/2912331.html
Copyright © 2011-2022 走看看