由于c#中的修改后的头文件

时间:2015-05-29 09:04:12

标签: c# c#-4.0 c#-3.0 c#-2.0

将网页浏览器控件中的网页保存到下面的代码目录中。现在我想检查每天修改或未修改的所有网页。如果它被修改必须更新或否则它。在这里我在控制台应用程序中尝试了一些东西。

static void Main(string[] args)
        {

            Uri myUri = new Uri("http://www.google.com");
            // Create a new 'HttpWebRequest' object with the above 'Uri' object.
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);

            // Create a new 'DateTime' object.
            DateTime targetDate = DateTime.Now;
            // Set a target date of a week ago
            targetDate.AddDays(-7.0);
            myHttpWebRequest.IfModifiedSince = targetDate;

            try
            {
                // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                Console.WriteLine("Response headers for recently modified page\n{0}\n", myHttpWebResponse.Headers);
                Stream streamResponse = myHttpWebResponse.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse);
                Char[] readBuff = new Char[256];
                int count = streamRead.Read(readBuff, 0, 256);
                Console.WriteLine("\nThe contents of Html Page are :  \n");

                while (count > 0)
                {
                    String outputData = new String(readBuff, 0, count);
                    Console.Write(outputData);
                    count = streamRead.Read(readBuff, 0, 256);
                }
                // Close the Stream object.
                streamResponse.Close();
                streamRead.Close();
                // Release the HttpWebResponse Resource.
                myHttpWebResponse.Close();

                Console.WriteLine("\nPress 'Enter' key to continue.................");
                Console.Read();
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotModified)
                    {
                        Console.WriteLine("\nThe page has not been modified since " + targetDate);
                        Console.ReadLine();
                    }
                    else
                        Console.WriteLine("\nUnexpected status code = " + ((HttpWebResponse)e.Response).StatusCode);
                      Console.ReadLine();
                }
                else
                    Console.WriteLine("\nUnexpected Web Exception " + e.Message);
                  Console.ReadLine();
            }
        }

我试过这个作为控制台应用程序,在这里我直接给了www.google.com。但我想从我的目录中查看我从网页浏览器控件中保存的内容。

 var filename1 = webBrowser1.Document.Title;

        var path1 = (@"D:\Cache\" + filename1 + ".html");
        if (mb != 1)
        {
            if (File.Exists(path1))
            {
                MessageBox.Show("Exist");
            }
            else
            {
                File.WriteAllText(path1, webBrowser1.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(webBrowser1.Document.Encoding));
                MessageBox.Show("Saved");
            }
        }

任何人都可以帮我完成此申请。在此先感谢。

0 个答案:

没有答案