转静态方法示例

简介:
< 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;
     }

}

本文转自 netcorner 博客园博客,原文链接: http://www.cnblogs.com/netcorner/archive/2007/07/20/2912331.html ,如需转载请自行联系原作者

相关文章
|
3月前
|
Java
java构造方法时对象初始化,实例化,参数赋值
java构造方法时对象初始化,实例化,参数赋值
96 1
|
3月前
|
Java
java中父类方法return this.对象还是变量,子类去调用this.这个方法的问题
本文探讨了在Java中,当父类的方法返回`this`对象或变量时,子类调用该方法的行为,以及`this`关键字在不同类中调用方法时的指向问题。
23 0
java中父类方法return this.对象还是变量,子类去调用this.这个方法的问题
|
7月前
|
Java
java反射-动态调用方法(无参无返回值、有参无返回值、有参有返回值)
java反射-动态调用方法(无参无返回值、有参无返回值、有参有返回值)
|
8月前
|
Java
【Java方法重载】 定义,使用,理解,示例解读
【Java方法重载】 定义,使用,理解,示例解读
191 0
|
Java
Java中构造方法的定义调用格式
Java中构造方法的定义调用格式
160 0
Java中构造方法的定义调用格式
|
程序员
Object类中的方法
Object类中的方法