网上看到很多人问NET生成HTML的相关技术,我以前也曾为这个问题伤脑筋很久,网上的很多是模版替换

字符的方法来实现,在实际的应用中,那样的方法根本就没有用。其实生成HTML的原理就是读取已经存在

的网站的HTML代码,再保存为其他文件,命名为****.htm或****.html。我自己写了一个类,使用很简单

,比较容易懂,也希望能给大家一点启示。

类名为schtml.cs

 

 

 1ASP.NET页面生成HTMLusing System; 
 2ASP.NET页面生成HTMLusing System.Data; 
 3ASP.NET页面生成HTMLusing System.Configuration; 
 4ASP.NET页面生成HTMLusing System.Web; 
 5ASP.NET页面生成HTMLusing System.Web.Security; 
 6ASP.NET页面生成HTMLusing System.Web.UI; 
 7ASP.NET页面生成HTMLusing System.Web.UI.HtmlControls; 
 8ASP.NET页面生成HTMLusing System.Web.UI.WebControls; 
 9ASP.NET页面生成HTMLusing System.Web.UI.WebControls.WebParts; 
10ASP.NET页面生成HTMLusing System.Web.Hosting; 
11ASP.NET页面生成HTMLusing System.IO; 
12ASP.NET页面生成HTMLusing System.Text; 
13ASP.NET页面生成HTMLusing System.Net; 
14ASP.NET页面生成HTML
15

 

使用方法也很简单

1ASP.NET页面生成HTML schtml html1 = new schtml(); 
2ASP.NET页面生成HTML  html1.creathtml("/product/default.aspx", Server.MapPath("http://www.cnblogs.com/product/"+ "index.htm");

 

 

html1.creathtml的两个参数说明一下:

前面一个是页面路径/product/default.aspx

后面一个Server.MapPath("http://www.cnblogs.com/product/") + "index.htm",是指要把生成的文件保存在哪个文件夹,此处是保存在product目录下,文件名为index.html

 

 

可以相互交流相互学习

 

 

相关文章: