public static bool WriteFile (string strText, string strContent, string strAuthor) {string path = HttpContext.Current.Server.MapPath ( "/ news /"); Encoding code = Encoding.GetEncoding ( "gb2312"); // read template File String Temp = httpContext.current.server.mappath ("/ news / text.html"); streamReader sr = null; streamwriter sw = null; string str = ""; try {sr = new streamreader (TEMP, CODE); Str = sr.readToEnd (); // Read file} catch (exception exp) {httpContext.current.response.write (exp.Message); httpcontext.current.response.end (); sr.close ();} String htmlfilename = datetime.now.tostring ("YYYYMMDDHHMMSS") ". html"; // Replace content // This time, the template file has been read into the variable name STR str = str.replace ("ShowArticle" STRTEXT); // ShowArticle Str = Str.Replace ("Biaoti", StRTEXT); Str = Str.Replace ("Author); Str.Replace (" Author ", StrauThor); Str = Str.Replace // write file try {sw = new streamwriter (Path HTMLFileName, False, Code); SW.WRITE (STR); sw.flush ();} catch (Excepti ON EX) {httpContext.current.response.write (EX.MESSAGE); httpContext.current.Response.end ();} finally {sw.close ();} return true;
This function is placed in the CONN.CS base class to add a reference to the code to add news: Engine name is HOVER IF (Hover.Conn.writeFileThis.title.Text.toString), this.content.Text.toString, this. Author.Text.toString))))) {response.write ("Add success");} else {response.write ("Generate HTML error!");} --------------- -------------------------------------------------- -------- Template page Text.html code ---------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------