• 转静态方法示例


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

    }

  • 相关阅读:
    每日Linux命令不完整命令
    mysql安装
    自动调用杀毒软件对文件进行杀毒
    正则获得字符串数组,以字符串分隔获取
    利用SQL语句查找某数据库中所有存储过程包含的内容
    TextBox的滚动条自动到最底部、利用枚举获取HashTable中的值
    Ajax中如何使用Session变量,Cookies可以用表单验证的方式获取并使用。
    用SQL语句批量生成一个表的INSERT语句
    利用DataSet、DataTable、DataView按照自定义条件过滤数据
    向线程传递数据与线程用回调方法检索数据
  • 原文地址:https://www.cnblogs.com/netcorner/p/2912331.html
Copyright © 2020-2023  润新知