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

在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;
        }

0
0
(请您对文章做出评价)
« 上一篇:C# 泛型和 C++ 模板
» 下一篇:在asp.net中实现多选
posted @ 2008-08-03 12:54 WUYQ 阅读(57) 评论(2)  编辑 收藏 所属分类: C#, asp.net

  回复  引用    
#1楼2009-06-18 17:57 | viq[未注册用户]
UpdateHtmlPage方法里的
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]);
}
这里没懂啊,能给我写上备注吗,看不懂string[] strStartHtml, string[] strEndHtml,这两参数分别是什么

  回复  引用  查看    
#2楼2009-07-26 22:16 | Vitor      
对啊
没搞明白四个参数的意思额