基本信息
源码名称:生成静态文件
源码大小:0.04M
文件格式:.rar
开发语言:C#
更新时间:2016-06-12
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
网站生成静态页面用的

 static void Main(string[] args)
        {
            Console.WriteLine("-------------Start-------------");
            Console.WriteLine("-------------请输入生成新闻(A), -------------");
            ConsoleKeyInfo ck = Console.ReadKey();
            if (ck.Key == ConsoleKey.A) {
                Console.WriteLine("");
                MakeHtmlFile();
            }

            Console.WriteLine("-------------End-------------");
            Console.Beep();
            Console.ReadLine();
        }
        public static int MakeHtmlFile()
        {
            //获取文章路径
            Console.WriteLine("-------------请输入起始新闻id: -------------");
            string first = Console.ReadLine();
            Console.WriteLine("-------------请输入结束新闻id: -------------");
            string second = Console.ReadLine();
            BaseClass bc = new BaseClass();
            string weburl = "http://news.panjiayuan.com";
            string sqlp = "select addtime,id from news where id >=" first " and id <=" second;
            DataTable dsp = bc.GetDataSet(sqlp).Tables[0];
            string pageurl = string.Empty;
            int num = 0;
            foreach (DataRow dr in dsp.Rows)
            {
                DateTime dtAddTime = Convert.ToDateTime(dr[0].ToString());
                string path = dtAddTime.ToString("yyyy") "\\" dtAddTime.ToString("MM");

                //string ArtCreatePath = ConfigurationManager.AppSettings["ArtCreatePath"].ToString() path;
                //string ArtCreatePath = "G:\\Category\\" path;
                string ArtCreatePath = "\\\\118.1\\Newscom\\" path;
                
                //创建文件夹
                DirectoryInfo site = new DirectoryInfo(ArtCreatePath);
                if (!site.Exists)
                {
                    site.Create();
                }
                DateTime dt = new DateTime();
                pageurl = weburl "/info/news.aspx?siteControl=news&t=" dt.Ticks "&newsid=" dr[1].ToString() "";
                WebRequest request = WebRequest.Create(pageurl);
                WebResponse response = request.GetResponse();
                Stream resstream = response.GetResponseStream();
                StreamReader sr = new StreamReader(resstream, System.Text.Encoding.GetEncoding("utf-8"));
                string contenthtml = sr.ReadToEnd();
                resstream.Close();
                sr.Close(); // 写入文件
                System.IO.StreamWriter sw;
                //sw = new System.IO.StreamWriter("G:\\Category\\" path "\\" dr[1].ToString() ".html", false, System.Text.Encoding.GetEncoding("utf-8"));
                sw = new System.IO.StreamWriter("\\\\118.\\News.p\\" path "\\" dr[1].ToString() ".html", false, System.Text.Encoding.GetEncoding("utf-8"));
                
                sw.Write(contenthtml);
                sw.Close();
                num ;
                Console.WriteLine(num.ToString() "/" pageurl);
            }

            return num;
        }