一个自动生成html的类
可以自动读取模板文件后,生成 当前 年/月/日/yyMMddhhmmss.html
代码如下
C#
1
private bool CreateHtml(string strText,string strContent,string strAuthor)
2
{
3
string yearString=DateTime.Now.Year.ToString();
4
string monthString=DateTime.Now.Month.ToString();
5
string dayString=DateTime.Now.Day.ToString();
6![](/Images/OutliningIndicators/InBlock.gif)
7
string fileName=yearString+monthString+dayString+DateTime.Now.Millisecond.ToString()+".html";
8
Directory.CreateDirectory(Server.MapPath(""+yearString+"//"+monthString+"//"+dayString+""));
9
10
Encoding code=Encoding.GetEncoding("gb2312");
11
string temp=Server.MapPath("text.html");
12
StreamReader sr=null;
13
StreamWriter sw=null;
14
string str="";
15
//读取模板
16
try
17
{
18
sr=new StreamReader(temp,code);
19
str=sr.ReadToEnd();
20
}
21
catch(Exception exp)
22
{
23
Response.Write(exp.Message);
24
Response.End();
25
sr.Close();
26
}
27
//替换
28
str=str.Replace("ShowArticle",strText);
29
str=str.Replace("biaoti",strText);
30
str=str.Replace("content",strContent);
31
str=str.Replace("author",strAuthor);
32
33
try
34
{
35![](/Images/OutliningIndicators/InBlock.gif)
36
sw=new StreamWriter(Server.MapPath(""+yearString+"//"+monthString+"//"+dayString+"//"+fileName+""),false,code);
37
sw.Write(str);
38
sw.Flush();
39
}
40
catch(Exception exp)
41
{
42
HttpContext.Current.Response.Write(exp.Message);
43
HttpContext.Current.Response.End();
44
}
45
finally
46
{
47
sw.Close();
48
}
49
return true;
50![](/Images/OutliningIndicators/InBlock.gif)
51
}
52![](/Images/OutliningIndicators/None.gif)
html页代码![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
52
![](/Images/OutliningIndicators/None.gif)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>ShowArticle</title>
</head>
<body>
biaoti
<br>
content<br>
author
</body>
</html>
<html>
<head>
<title>ShowArticle</title>
</head>
<body>
biaoti
<br>
content<br>
author
</body>
</html>