tohtml.cs 【生成静态页面核心类】:using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Net;
using System.Text;
using System.IO;
namespace stroper
{
public class tohtml
{
public tohtml()
{
}
/// <summary>
/// 生成静态网页
/// </summary>
/// <param name="template_url">模板相对路径</param>
/// <param name="Come_url">生成静态页面的相对路径</param>
/// <param name="encode">页面编码</param>
/// <param name="tags">静态模板标签</param>
/// <param name="chg_tags">替换标签的内容</param>
public string chg_html(string template_url,string Come_url,string encode,string[] tags,string[] chg_tags)
{
//初始化html字节流
string init_stream = readsr(System.Web.HttpContext.Current.Server.MapPath(template_url), encode);
//生成文件名
string fileName=get_filename();
//完成html字节流
string ok_streamstr = chg_tag(tags, chg_tags, init_stream);
//生成存放html的文件夹
fileoper files = new fileoper();
files.CreateFolder(Come_url);
//生成静态页面
bool okout = outhtml(System.Web.HttpContext.Current.Server.MapPath(Come_url)+"\\" + fileName, encode, ok_streamstr);
//判断生成成功与失败
if (okout == true)
{
return System.Web.HttpContext.Current.Server.MapPath(Come_url) + "\\" + fileName;
}
else
{
return "生成失败";
}
}
/// <summary>
/// 读取文件字节流
/// </summary>
/// <param name="template_url">模板相对路径</param>
/// <param name="encode">页面编码</param>
/// <returns>template静态模板的html字符串</returns>
private string readsr(string template_url, string encode)
{
Encoding code = Encoding.GetEncoding(encode);
StreamReader sr = null;
string str = null;
//读取
try
{
sr = new StreamReader(template_url, code);
str = sr.ReadToEnd();
return str;
&n