网上看到很多人问NET生成HTML的相关技术,我以前也曾为这个问题伤脑筋很久,网上的很多是模版替换
字符的方法来实现,在实际的应用中,那样的方法根本就没有用。其实生成HTML的原理就是读取已经存在
的网站的HTML代码,再保存为其他文件,命名为****.htm或****.html。我自己写了一个类,使用很简单
,比较容易懂,也希望能给大家一点启示。
类名为schtml.cs
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.HtmlControls;
8
using System.Web.UI.WebControls;
9
using System.Web.UI.WebControls.WebParts;
10
using System.Web.Hosting;
11
using System.IO;
12
using System.Text;
13
using System.Net;
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
使用方法也很简单
1
schtml html1 = new schtml();
2
html1.creathtml("/product/default.aspx", Server.MapPath("http://www.cnblogs.com/product/") + "index.htm");
2
html1.creathtml的两个参数说明一下:
前面一个是页面路径/product/default.aspx
后面一个Server.MapPath("http://www.cnblogs.com/product/") + "index.htm",是指要把生成的文件保存在哪个文件夹,此处是保存在product目录下,文件名为index.html
可以相互交流相互学习