private
void
CreateHtmlFile()
5
{
6
/**////定义和html标记数目一致的数组
7
string[] newContent = new string[5];
8
StringBuilder strhtml = new StringBuilder();
9
try
10
{
11
/**////创建StreamReader对象
12
using (StreamReader sr = new StreamReader(Server.MapPath("createHTML") + "//template.html"))
13
{
14
String oneline;
15
16
/**////读取指定的HTML文件模板
17
while ((oneline = sr.ReadLine()) != null)
18
{
19
strhtml.Append(oneline);
20
}
21
sr.Close();
22
}
23
}
24
catch(Exception err)
25
{
26
/**////输出异常信息
27
Response.Write(err.ToString());
28
}
29
/**////为标记数组赋值
30
newContent[0] = txtTitle.Text;//标题
31
newContent[1] = "BackColor='#cccfff'";//背景色
32
newContent[2] = "#ff0000";//字体颜色
33
newContent[3] = "100px";//字体大小
34
newContent[4] = txtContent.Text;//主要内容
35
36
/**////根据上面新的内容生成html文件
37
try
38
{
39
/**////指定要生成的HTML文件
40
string fname = Server.MapPath("createHTML") +"//" + DateTime.Now.ToString("yyyymmddhhmmss") + ".html";
41
42
/**////替换html模版文件里的标记为新的内容
43
for(int i=0;i < 5;i++)
44
{
45
strhtml.Replace("$htmlkey["+i+"]",newContent[i]);
46
}
47
/**////创建文件信息对象
48
FileInfo finfo = new FileInfo(fname);
49
50
/**////以打开或者写入的形式创建文件流
51
using(FileStream fs = finfo.OpenWrite())
52
{
53
/**////根据上面创建的文件流创建写数据流
54
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));
55
56
/**////把新的内容写到创建的HTML页面中
57
sw.WriteLine(strhtml);
58
sw.Flush();
59
sw.Close();
60
}
61
62
/**////设置超级链接的属性
63
hyCreateFile.Text = DateTime.Now.ToString("yyyymmddhhmmss")+".html";
64
hyCreateFile.NavigateUrl = "createHTML/"+DateTime.Now.ToString("yyyymmddhhmmss")+".html";
65
}
66
catch(Exception err)
67
{
68
Response.Write (err.ToString());
69
}
70
}
5



6


7

8

9

10



11


12

13



14

15

16


17

18



19

20

21

22

23

24

25



26


27

28

29


30

31

32

33

34

35

36


37

38



39


40

41

42


43

44



45

46

47


48

49

50


51

52



53


54

55

56


57

58

59

60

61

62


63

64

65

66

67



68

69

70
