Asp.NET Éú³É¾²Ì¬Ò³ »·¾³:Microsoft .NET Framework SDK v1.1 OS:Windows Server 2003 ÖÐÎİæ ASP.NetÉú³É¾²Ì¬HTMLÒ³ ÔÚAspÖÐʵÏÖµÄÉú³É¾²Ì¬Ò³Óõ½µÄFileSystemObject¶ÔÏó! ÔÚ.NetÖÐÉæ¼°´ËÀà²Ù×÷µÄÊÇSystem.IO ÒÔÏÂÊdzÌÐò´úÂë ×¢:´Ë´úÂë·ÇÔ´´!²Î¿¼±ðÈË´úÂë //Éú³ÉHTMLÒ³ public static bool WriteFile(string strText,string strContent,string strAuthor) { string path = HttpContext.Current.Server.MapPath("/news/"); Encoding code = Encoding.GetEncoding("gb2312"); // ¶Áȡģ°åÎļþ 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(); // ¶ÁÈ¡Îļþ } catch(Exception exp) { HttpContext.Current.Response.Write(exp.Message); HttpContext.Current.Response.End(); sr.Close(); } string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html"; // Ìæ»»ÄÚÈÝ // Õâʱ,Ä£°åÎļþÒѾ¶ÁÈëµ½Ãû³ÆÎªstrµÄ±äÁ¿ÖÐÁË str =str.Replace("ShowArticle",strText); //Ä£°åÒ³ÖеÄShowArticle str = str.Replace("biaoti",strText); str = str.Replace("content",strContent); str = str.Replace("author",strAuthor); // дÎļþ try { sw = new StreamWriter(path + htmlfilename , false, code); sw.Write(str); sw.Flush(); } catch(Exception ex) { HttpContext.Current.Response.Write(ex.Message); HttpContext.Current.Response.End(); } finally { sw.Close(); } return true;
´Ëº¯Êý·ÅÔÚConn.CS»ùÀàÖÐÁË ÔÚÌí¼ÓÐÂÎŵĴúÂëÖÐÒýÓà ע£º¹¤³ÌÃûΪHover if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString))) { Response.Write("Ìí¼Ó³É¹¦"); } else { Response.Write("Éú³ÉHTML³ö´í!"); } Ä£°åÒ³Text.html´úÂë <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>ShowArticle</title> <body> biaoti <br> content<br> author </body> </HTML> biaoti <br> content<br> author </body> </HTML>
|