在asp.net中生成html文件代码

原创 2008年08月03日 13:10:00

在asp.net中生成html文件代码如下

public static bool CreatHtmlPage(string[] strNewsHtml, string[] strOldHtml, string strModeFilePath, string strPageFilePath)
        {
            bool Flage = false;
            StreamReader ReaderFile = null;
            StreamWriter WrirteFile = null;
            //修改mode.htm到inc目录下
           strModeFilePath = "../inc/" + strModeFilePath;
            string FilePath = HttpContext.Current.Server.MapPath(strModeFilePath);
            Encoding Code = Encoding.GetEncoding("gb2312");
            string strFile = string.Empty;
            try
            {
                ReaderFile = new StreamReader(FilePath, Code);
                strFile = ReaderFile.ReadToEnd();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ReaderFile.Close();
            }
            try
            {
                int intLengTh = strNewsHtml.Length;
                for (int i = 0; i < intLengTh; i++)
                {
                    strFile = strFile.Replace(strOldHtml[i], strNewsHtml[i]);
                }
                WrirteFile = new StreamWriter(HttpContext.Current.Server.MapPath(strPageFilePath), false, Code);
                WrirteFile.Write(strFile);
                Flage = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                WrirteFile.Flush();
                WrirteFile.Close();
            }
            return Flage;
        }
        public static bool UpdateHtmlPage(string[] strNewsHtml, string[] strStartHtml, string[] strEndHtml, string strHtml)
        {
            bool Flage = false;
            StreamReader ReaderFile = null;
            StreamWriter WrirteFile = null;
            string FilePath = HttpContext.Current.Server.MapPath(strHtml);
            Encoding Code = Encoding.GetEncoding("gb2312");
            string strFile = string.Empty;
            try
            {
                ReaderFile = new StreamReader(FilePath, Code);
                strFile = ReaderFile.ReadToEnd();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ReaderFile.Close();
            }
            try
            {
                int intLengTh = strNewsHtml.Length;
                for (int i = 0; i < intLengTh; i++)
                {
                    int intStart = strFile.IndexOf(strStartHtml[i]) + strStartHtml[i].Length;
                    int intEnd = strFile.IndexOf(strEndHtml[i]);
                    string strOldHtml = strFile.Substring(intStart, intEnd - intStart);
                    strFile = strFile.Replace(strOldHtml, strNewsHtml[i]);
                }
                WrirteFile = new StreamWriter(FilePath, false, Code);
                WrirteFile.Write(strFile);
                Flage = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                WrirteFile.Flush();
                WrirteFile.Close();
            }
            return Flage;
        }

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Asp.net生成html文件源码

  • 2007-12-19 14:03
  • 69KB
  • 下载

ASP生成静态Html文件技术

现在网站网页生成静态Html文件有许多好处,比如生成html网页有利于被搜索引擎收录,不仅被收录的快还收录的全.前台脱离了数据访问,减轻对数据库访问的压力,加快网页打开速度.  像www.aspid...

ASP生成静态Html文件技术杂谈

ASP生成静态Html文件技术杂谈 网页生成静态Html文件有许多好处,比如生成html网页有利于被搜索引擎收录,不仅被收录的快还收录的全.前台脱离了数据访问,减轻对数据库访问的压力,加快网页打开速度...

Asp.net生成html文件

【ASP】ASP vbscript一个综合的例子,操作html文件添加、删除代码、删除文件。

后台管理 添加文章 文章标题: 文章内容: 删除文章 文章编号: 文章标题: 创建日期: <% Dim fso,htmlwrite,countwrite...

Asp.net生成html文件

  • 2009-05-14 13:26
  • 69KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)