title: Downloading file from url with timeout
body: <p>I'm writing a program in Visual Studio 2010 using C# .Net</p>
  
  <p>The program is to save the file from a given url to local drive, with a custom timeout to save time.</p>
  
  <p>Say the url is <code>http://mywebsite.com/file1.pdf</code>, and I want to save the file to the directory <code>C:\downloadFiles\</code></p>
  
  <p>Currently, I'm using <code>WebClient</code>.</p>
  
  <pre><code>WebClient.DownloadFile("http://mywebsite.com/file1.pdf", "C:\downloadFiles\file1.pdf");
  </code></pre>
  
  <p>I am able to save the file, but I ran into some problem.</p>
  
  <p>Sometimes, the url just won't respond, so I have my program try to download 5 times before terminating. I then realize the default timeout for WebClient is too long for my need (like 2 min or something) Is there a simple way to set timeout shorter, say like 15 sec?</p>
  
  <p>I also looked into <code>HttpWebRequest</code>, which I can easily set the timeout <code>HttpWebRequest.Timeout = 15000;</code>. However, with this method, I have no idea how I can download/save the file.</p>
  
  <p><strong>So my over all questions is:</strong> Which is more simple, setting timeout for <code>WebClient</code>, or saving file using <code>HttpWebRequest</code>? And how would I go about doing so?</p>