黑夜的狼

沮丧吗,那就是一种无病呻吟!留恋它就是一种高度近视!目光应该放得更远一点! 别不想飞,只是要一步跨过太平洋!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

    public class createDetailHtml
    {
        private string strType;
        public string _strType
        {
               set{strType=value;}
        }
        public createDetailHtml()
        {
               strType=Date.now.year.ToString()+Date.now.month.ToString();
        }
        public bool getFile(string url, string strType, string pageName)
        {
            WebClient wc = new WebClient();
            wc.Encoding = System.Text.Encoding.GetEncoding("gb2312");
            byte[] buffer = null;
            StreamWriter sw = null;
            try
            {
                buffer = wc.DownloadData(url);
                sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/" + strType + "/" + pageName), false, System.Text.Encoding.GetEncoding("gb2312"));
                sw.Write(System.Text.Encoding.GetEncoding("gb2312").GetString(buffer));
                sw.Flush();
                sw.Close();
                return true;
            }
            catch (Exception ex)
            {
                System.Web.HttpContext.Current.Response.Write(ex);
                System.Web.HttpContext.Current.Response.Write("<font color=red>生成失败,请重新生成!!</font>");
                return false;
            }
            finally
            {
                wc.Dispose();

            }
        }
    }

这个类我一般用在生成单个静态页面,比如添加一个编文章,马上生成,比较方便
水平有限,有误请留言

posted on 2007-10-16 16:56  anncesky  阅读(487)  评论(0编辑  收藏  举报