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;
            }
        }
  • 相关阅读:
    Ubuntu16.04编译Android6.0/cm13.0教程及相关错误解决办法
    TWRP基于omnirom 6.0.1编译教程
    教你一招:解决Win 10安装软件时提示:文件系统错误 (-1073740940)
    红米3 TWRP-3.0.2(android_6.0.1_r72分支)中文版Recovery更新于20161018
    C# Note32: 查漏补缺
    postgreSQL使用杂谈
    Granfana+PostgreSQL
    WIndows下使用Grafana+InfluxDB打造监控系统
    【译】历史上的名人如何利用不同的思维方式成就自己
    【译】Focused and Diffuse Modes(专注与发散模式)
  • 原文地址:https://www.cnblogs.com/cosiray/p/1558515.html
Copyright © 2011-2022 走看看