1 /// <summary>
2 /// 替换模板中的文字的方法
3 /// </summary>
4 /// <param name="str01">要替换为的内容</param>
5 /// <param name="mm">模板的名称</param>
6 /// <param name="mmm">替换以后要生成的文件的名字</param>
7 /// <returns></returns>
8 public bool WriteFile(string str01, string mm, string mmm)
9 {
10
11 string path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString());
12 Encoding code = Encoding.GetEncoding("GB2312");
13 string temp = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString() + mm);
14 StreamReader sr = null;
15 StreamWriter st = null;
16 string str = "";
17 try
18 {
19 sr = new StreamReader(temp, code);
20 str = sr.ReadToEnd();
21
22 }
23 catch (Exception ex)
24 {
25 HttpContext.Current.Response.Write(ex.Message);
26 HttpContext.Current.Response.End();
27 sr.Close();
28 }
29 string htmlfilename = mmm;
30 str = str.Replace("content", str01);
31 try
32 {
33 st = new StreamWriter(path + htmlfilename, false, code);
34 st.Write(str);
35 st.Flush();
36 }
37 catch (Exception ex)
38 {
39 HttpContext.Current.Response.Write(ex.Message);
40 HttpContext.Current.Response.End();
41 }
42 finally
43 {
44 st.Close();
45 }
46 return true;
47 }
48
49 //替换多个地方的方法
50 private bool WriteFile(DataGrid dgName01, DataGrid dgName02, DataGrid dgName03, DataGrid dgName04, DataGrid dgName05, DataGrid dgName06, DataGrid dgName07)
51 {
52 string path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString());
53 Encoding code = Encoding.GetEncoding("GB2312");
54 string temp = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString() + "index.html");
55 StreamReader sr = null;
56 StreamWriter st = null;
57 string str = "";
58 try
59 {
60 sr = new StreamReader(temp, code);
61 str = sr.ReadToEnd();
62
63 }
64 catch (Exception ex)
65 {
66 HttpContext.Current.Response.Write(ex.Message);
67 HttpContext.Current.Response.End();
68 sr.Close();
69 }
70 string htmlfilename = "search.html";
71 str = str.Replace("content01", ToRead(this.DataGrid1));
72 str = str.Replace("content02", ToRead(this.DataGrid2));
73 str = str.Replace("content03", ToRead(this.DataGrid3));
74 str = str.Replace("content04", ToRead(this.DataGrid4));
75 str = str.Replace("content05", ToRead(this.DataGrid5));
76 str = str.Replace("content06", ToRead(this.DataGrid6));
77 str = str.Replace("content07", ToRead(this.DataGrid7));
78 try
79 {
80 st = new StreamWriter(path + htmlfilename, false, code);
81 st.Write(str);
82 st.Flush();
83 }
84 catch (Exception ex)
85 {
86 HttpContext.Current.Response.Write(ex.Message);
87 HttpContext.Current.Response.End();
88 }
89 finally
90 {
91 st.Close();
92 }
93 return true;
94 }
2 /// 替换模板中的文字的方法
3 /// </summary>
4 /// <param name="str01">要替换为的内容</param>
5 /// <param name="mm">模板的名称</param>
6 /// <param name="mmm">替换以后要生成的文件的名字</param>
7 /// <returns></returns>
8 public bool WriteFile(string str01, string mm, string mmm)
9 {
10
11 string path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString());
12 Encoding code = Encoding.GetEncoding("GB2312");
13 string temp = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString() + mm);
14 StreamReader sr = null;
15 StreamWriter st = null;
16 string str = "";
17 try
18 {
19 sr = new StreamReader(temp, code);
20 str = sr.ReadToEnd();
21
22 }
23 catch (Exception ex)
24 {
25 HttpContext.Current.Response.Write(ex.Message);
26 HttpContext.Current.Response.End();
27 sr.Close();
28 }
29 string htmlfilename = mmm;
30 str = str.Replace("content", str01);
31 try
32 {
33 st = new StreamWriter(path + htmlfilename, false, code);
34 st.Write(str);
35 st.Flush();
36 }
37 catch (Exception ex)
38 {
39 HttpContext.Current.Response.Write(ex.Message);
40 HttpContext.Current.Response.End();
41 }
42 finally
43 {
44 st.Close();
45 }
46 return true;
47 }
48
49 //替换多个地方的方法
50 private bool WriteFile(DataGrid dgName01, DataGrid dgName02, DataGrid dgName03, DataGrid dgName04, DataGrid dgName05, DataGrid dgName06, DataGrid dgName07)
51 {
52 string path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString());
53 Encoding code = Encoding.GetEncoding("GB2312");
54 string temp = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ADDRESS"].ToString() + "index.html");
55 StreamReader sr = null;
56 StreamWriter st = null;
57 string str = "";
58 try
59 {
60 sr = new StreamReader(temp, code);
61 str = sr.ReadToEnd();
62
63 }
64 catch (Exception ex)
65 {
66 HttpContext.Current.Response.Write(ex.Message);
67 HttpContext.Current.Response.End();
68 sr.Close();
69 }
70 string htmlfilename = "search.html";
71 str = str.Replace("content01", ToRead(this.DataGrid1));
72 str = str.Replace("content02", ToRead(this.DataGrid2));
73 str = str.Replace("content03", ToRead(this.DataGrid3));
74 str = str.Replace("content04", ToRead(this.DataGrid4));
75 str = str.Replace("content05", ToRead(this.DataGrid5));
76 str = str.Replace("content06", ToRead(this.DataGrid6));
77 str = str.Replace("content07", ToRead(this.DataGrid7));
78 try
79 {
80 st = new StreamWriter(path + htmlfilename, false, code);
81 st.Write(str);
82 st.Flush();
83 }
84 catch (Exception ex)
85 {
86 HttpContext.Current.Response.Write(ex.Message);
87 HttpContext.Current.Response.End();
88 }
89 finally
90 {
91 st.Close();
92 }
93 return true;
94 }