zoukankan      html  css  js  c++  java
  • ASP.NET C#生成HTML页类

        /// <summary>
        /// 生成HTML页类
        /// </summary>
        public class ProduceHtmlPage
        {
            public static bool WriteFile(string strTopic,string strArticleClass,string strArticleClassChild,string strContent,string strSource,string strAuthor,string strEditor,string strPubDate,string strPageUrl)
            {
                string path = HttpContext.Current.Server.MapPath("/bluedn/html/");
                Encoding code = Encoding.GetEncoding("gb2312");
                //读取模板文件
                string temp = HttpContext.Current.Server.MapPath("/bluedn/template/NewsInfo.htm");
                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= strPageUrl+".htm";
                //DateTime.Now.ToString("yyyyMMddHHmmss")+".htm";
                //替换内容
                //这时,模板文件已经读入到名称为str的变量中了

                //模板页中的新闻标题
                str = str.Replace("$t_Topic$",strTopic);
                //一级栏目
                str = str.Replace("$t_ArticleClass$",strArticleClass);
                //二级栏目
                str = str.Replace("$t_ArticleClassChild$",strArticleClassChild);
                //新闻来源
                str = str.Replace("$t_Source$",strSource);
                //作者
                str = str.Replace("$t_Author$",strAuthor);
                //编辑
                str = str.Replace("$t_Editor$",strEditor);
                //发布日期
                str = str.Replace("$t_PubDate$",strPubDate);
                //新闻内容
                str = str.Replace("$t_Content$",strContent);

                //写文件
                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;
            }
        }
  • 相关阅读:
    实例图解SQL SERVER2000使用AWE进行内存优化
    使用Power Designer正反向数据库及生成设计报告
    使用SVN+CruiseControl+ANT实现持续集成之二环境搭建和配置介绍
    使用SVN+CruiseControl+ANT实现持续集成之三构建操作及监视
    【排序】排序算法之分配排序
    [Cocoa]自定义TableViewCell实现圆角/渐变色TableView
    [Cocoa]XCode 3.2 常用快捷键
    [Cocoa]实现了一套自定义动画库
    Vim 使用入门快捷键
    [Cocoa] iPhone/iPad 时区转换
  • 原文地址:https://www.cnblogs.com/cosiray/p/1558515.html
Copyright © 2011-2022 走看看