问题描述
asp.net生成静态页环境:microsoft.netframeworksdkv1.1os:windowsserver2003中文版asp.net生成静态html页在asp中实现的生成静态页用到的filesystemobject对象!在.net中涉及此类操作的是system.io以下是程序代码注:此代码非原创!参考别人代码//生成html页publicstaticboolwritefile(stringstrtext,stringstrcontent,stringstrauthor){stringpath=httpcontext.current.server.mappath("/news/");encodingcode=encoding.getencoding("gb2312");//读取模板文件stringtemp=httpcontext.current.server.mappath("/news/text.html");streamreadersr=null;streamwritersw=null;stringstr="";try{sr=newstreamreader(temp,code);str=sr.readtoend();//读取文件}catch(exceptionexp){httpcontext.current.response.write(exp.message);httpcontext.current.response.end();sr.close();}stringhtmlfilename=datetime.now.tostring("yyyymmddhhmmss")+".html";//替换内容//这时,模板文件已经读入到名称为str的变量中了str=str.replace("showarticle",strtext);//模板页中的showarticlestr=str.replace("biaoti",strtext);str=str.replace("content",strcontent);str=str.replace("author",strauthor);//写文件try{sw=newstreamwriter(path+htmlfilename,false,code);sw.write(str);sw.flush();}catch(exceptionex){httpcontext.current.response.write(ex.message);httpcontext.current.response.end();}finally{sw.close();}returntrue;此函数放在conn.cs基类中了在添加新闻的代码中引用注:工程名为hoverif(hover.conn.writefilethis.title.text.tostring),this.content.text.tostring),this.author.text.tostring))){response.write("添加成功");}else{response.write("生成html出错!");}模板页text.html代码<!doctypehtmlpublic"-//w3c//dtdhtml4.0transitional//en"><html><head><title>showarticle</title><body>biaoti<br>content<br>author</body></html>biaoti<br>content<br>author</body></html>文章来源http://softbbs.pconline.com.cn/topic.jsp?tid=7625181
解决方案
解决方案二:
毛遂自荐www.ebookit.cn