title: how to get html page source by C#
body: <p>I want to save complete web page asp in local drive by <code>.htm</code> from <a href="https://www.digikala.com/Search/Category-Motherboard/#!/Category-Electronic-Devices/Category-Computer-Parts/Category-Computer-Devices/Category-Motherboard/" rel="nofollow noreferrer">url</a> or <a href="https://www.digikala.com" rel="nofollow noreferrer">url</a> but I did not success.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public StreamReader Fn_DownloadWebPageComplete(string link_Pagesource)
  {
       //--------- Download Complete ------------------
       //  using (WebClient client = new WebClient()) // WebClient class inherits IDisposable
       //   {
  
       //client
       //HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(link_Pagesource);
  
                      //webRequest.AllowAutoRedirect = true;
                      //var client1 = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(link_Pagesource);
                      //client1.CookieContainer = new System.Net.CookieContainer();
  
  
                   //   client.DownloadFile(link_Pagesource, @"D:\S1.htm");
  
                //  }
           //--------- Download Page Source ------------------
   HttpWebRequest URL_pageSource = (HttpWebRequest)WebRequest.Create("https://www.digikala.com");
  
                      URL_pageSource.Timeout = 360000;
                      //URL_pageSource.Timeout = 1000000;
                      URL_pageSource.ReadWriteTimeout = 360000;
                     // URL_pageSource.ReadWriteTimeout = 1000000;
                      URL_pageSource.AllowAutoRedirect = true;
                      URL_pageSource.MaximumAutomaticRedirections = 300;
  
                      using (WebResponse MyResponse_PageSource = URL_pageSource.GetResponse())
                      {
  
                          str_PageSource = new StreamReader(MyResponse_PageSource.GetResponseStream(), System.Text.Encoding.UTF8);
                          pagesource1 = str_PageSource.ReadToEnd();
                          success = true;
                      }
  </code></pre>
  
  <p>Error :</p>
  
  <blockquote>
    <p>Too many automatic redirections were attempted.</p>
  </blockquote>
  
  <p>Attemp by this codes but not successful.</p>
  
  <p>many url is successful with this codes but this url not successful.</p>