title: How to download a file from a URL using c#
body: <p>I want to download a .xlsx file from below address.
  <a href="http://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=1396-08-08" rel="nofollow noreferrer">http://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=1396-08-08</a> </p>
  
  <p>by clicking on the link automatically a file will be downloaded by the browser. I tried to download the file from this codes:</p>
  
  <pre><code>using (var client = new WebClient())
  {
        client.DownloadFile("http://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=1396-08-08", @"D:\Archive\1396-08-08.xlsx");
  } 
  </code></pre>
  
  <p>But it will download a weird file different from the file downloaded by the browser at first step. </p>
  
  <p>Also I tried :</p>
  
  <pre><code>System.Diagnostics.Process.Start(
  "http://members.tsetmc.com/tsev2/excel/MarketWatchPlus.aspx?d=0");
  </code></pre>
  
  <p>But this code has two disadvantages:</p>
  
  <p>1- It opens a browser which is not required.</p>
  
  <p>2- I can't determine any path or file name for the downloaded file.</p>
  
  <p>I want to gain exactly the same file that will be downloaded by clicking on the above link address. 
  How can I download my required file? </p>
  
  <p><a href="https://i.stack.imgur.com/jY7NT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jY7NT.png" alt="Currupted file"></a>
  <a href="https://i.stack.imgur.com/qV6Jr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qV6Jr.png" alt="Correct File"></a></p>