how are you creating those static pages? use a tool? add some special tags or comments like <!--start insert 1 --><!--end insert 1 --> inside those static pages and write a parser (using regular expression, for example) to insert information in those tags
我现在用的是 StreamWriter outText = new StreamWriter(Server.MapPath(htmName),true,System.Text.Encoding.GetEncoding("GB2312"));可以在服务器上已经存在的html尾部添加内容, 但我必须在倒数第8行添加内容,怎样实现呢?
>>>>倒数第8行is not a good criteria, like I said earlier, insert some placeholder like<!--PUTMYCONTENTHERE-->then replace it with whatever you wantotherwise, you need to read all the content in, count the number of lines, find where 倒数第8行 is, insert the content..., very tedious to do
谢谢saucer(思归, MS .NET MVP) ,我明白您的意思。 我计划用StreamRead先把html文件读到一个string中, 然后string.Replace("<!--PUTMYCONTENTHERE-->","新增加内容<!--PUTMYCONTENTHERE-->");然后把这个string写回html方法对头吧?
<!--start insert 1 --><!--end insert 1 --> inside those static pages and write a parser (using regular expression, for example) to insert information in those tags
StreamWriter outText = new StreamWriter(Server.MapPath(htmName),true,System.Text.Encoding.GetEncoding("GB2312"));可以在服务器上已经存在的html尾部添加内容,
但我必须在倒数第8行添加内容,怎样实现呢?
我计划用StreamRead先把html文件读到一个string中,
然后string.Replace("<!--PUTMYCONTENTHERE-->","新增加内容<!--PUTMYCONTENTHERE-->");然后把这个string写回html方法对头吧?
1. make sure you have <!--Add Reply--> in your html code2. string is immutableNewHtml = NewHtml.Replace("<!--Add Reply-->",ReplyHtml);