日期:2014-05-17 浏览次数:20501 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Text;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string templateContent = ReadFile("Template/index.htm");
templateContent = templateContent.Replace("{content}", "新内容").Replace("{title}", "新标题");
CreateFile("Index.html", templateContent);
}
public static void CreateDir(string dir) {
if (dir.Length == 0) return;
string path = System.Web.HttpContext.Current.Request.MapPath("/");
if (!Directory.Exists(path + dir))
Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("/") + dir);
}
public static Boolean CreateFile(string dir, string pagestr) {
System.IO.StreamWriter sw = null;
try {
sw = new StreamWriter(HttpContext.Current.Request.MapPath("~/") + "\\" + dir, false, Encoding.GetEncoding("GB2312"));
sw.Write(pagestr);
}
catch (Exception ex) {
sw.Close();
sw.Dispose();
throw ex;
}
&nbs