An automatically generated classes html

After the template files can be automatically read, to generate the current year / month / day /yyMMddhhmmss.html

code show as below

C#

 1 None.gif private   bool   CreateHtml( string  strText, string  strContent, string  strAuthor)
 2 ExpandedBlockStart.gifContractedBlock.gif   dot.gif {
 3InBlock.gif   string yearString=DateTime.Now.Year.ToString();
 4InBlock.gif   string monthString=DateTime.Now.Month.ToString();
 5InBlock.gif   string dayString=DateTime.Now.Day.ToString();
 6InBlock.gif
 7InBlock.gif   string fileName=yearString+monthString+dayString+DateTime.Now.Millisecond.ToString()+".html";
 8InBlock.gif   Directory.CreateDirectory(Server.MapPath(""+yearString+"//"+monthString+"//"+dayString+""));
 9InBlock.gif  
10InBlock.gif   Encoding code=Encoding.GetEncoding("gb2312");
11InBlock.gif   string temp=Server.MapPath("text.html");
12InBlock.gif   StreamReader sr=null;
13InBlock.gif   StreamWriter sw=null;
14InBlock.gif   string str="";
15InBlock.gif   //读取模板
16InBlock.gif   try
17ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
18InBlock.gif    sr=new StreamReader(temp,code);
19InBlock.gif    str=sr.ReadToEnd();
20ExpandedSubBlockEnd.gif   }

21InBlock.gif   catch(Exception exp)
22ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
23InBlock.gif    Response.Write(exp.Message);
24InBlock.gif    Response.End();
25InBlock.gif    sr.Close();
26ExpandedSubBlockEnd.gif   }

27InBlock.gif   //替换
28InBlock.gif   str=str.Replace("ShowArticle",strText);
29InBlock.gif   str=str.Replace("biaoti",strText);
30InBlock.gif   str=str.Replace("content",strContent);
31InBlock.gif   str=str.Replace("author",strAuthor);
32InBlock.gif   
33InBlock.gif   try
34ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
35InBlock.gif
36InBlock.gif    sw=new StreamWriter(Server.MapPath(""+yearString+"//"+monthString+"//"+dayString+"//"+fileName+""),false,code);
37InBlock.gif    sw.Write(str);
38InBlock.gif    sw.Flush();
39ExpandedSubBlockEnd.gif   }

40InBlock.gif   catch(Exception exp)
41ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
42InBlock.gif    HttpContext.Current.Response.Write(exp.Message);
43InBlock.gif    HttpContext.Current.Response.End();
44ExpandedSubBlockEnd.gif   }

45InBlock.gif   finally
46ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
47InBlock.gif    sw.Close();
48ExpandedSubBlockEnd.gif   }

49InBlock.gif   return true;
50InBlock.gif
51ExpandedBlockEnd.gif  }

52 None.gif
 html page code
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< html >
 
< head >
  
< title > ShowArticle </ title >

 
</ head >
 
< body >
  biaoti
  
< br >
  content
< br >
  author
 
</ body >
</ html >

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2007/07/15/819128.html

Guess you like

Origin blog.csdn.net/weixin_33962923/article/details/93495943