using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.IO.Compression;
using System.IO.IsolatedStorage;
using System.IO.Ports;
using System.CodeDom.Compiler;
using System.CodeDom;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_OnClick(Object sender, EventArgs e)
{
string strContent = FCKeditor1.Value;
WriteFile(strContent);
}
public static bool WriteFile(string strContent)
{
string path = HttpContext.Current.Server.MapPath("~/webnews/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文档
string temp = HttpContext.Current.Server.MapPath("~/webnews/text .html");
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();
}
string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
// 替换内容
// 这时,模板文档已读入到名称为str的变量中了
str = str.Replace("content",strContent);
// 写文档
try
{
sw = new StreamWriter(path + htmlfilename , false, code);
sw.Write(str);
sw.Flush();
}
catch(Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
}
}