天天看點

轉靜态方法示例

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

             sw = new StreamWriter(HttpContext.Current.Server.MapPath("" + yearString + "//" + monthString + "//" + dayString + "//" + fileName + ""), false, code);

             sw.Write(str);

             sw.Flush();

         finally

             sw.Close();

         return true;

}

本文轉自 netcorner 部落格園部落格,原文連結: http://www.cnblogs.com/netcorner/archive/2007/07/20/2912331.html ,如需轉載請自行聯系原作者

繼續閱讀