title: How To Use HttpWebRequest/Response To Download A Binary (.exe) File From A Web Server?
body: <p>I am writing a program that needs to download an <code>.exe</code> file from a website and then save it to the hard drive. The <code>.exe</code> is stored on my site and it's url is as follows (it's not the real uri just one I made up for the purpose of this question):</p>
  
  <pre><code>http://www.mysite.com/calc.exe
  </code></pre>
  
  <p>After many web searches and fumbling through examples here is the code I have come up with so far:</p>
  
  <pre><code>HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(http://www.mysite.com/calc.exe);
  HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
  Stream responseStream = webResponse.GetResponseStream();               
  StreamReader streamReader = new StreamReader(responseStream);
  string s = streamReader.ReadToEnd();
  </code></pre>
  
  <p>As you can see I am using the <code>StreamReader</code> class to read the data. After calling <em><code>ReadToEnd</code></em> does the stream reader contain the (binary) content of my .exe? Can I just write the content of the <code>StreamReader</code> to a file (named calc.exe) and I will have succesfully downloaded the .exe?</p>
  
  <p>I am wondering why <code>StreamReader</code> <em><code>ReadToEnd</code></em> returns a string. In my case would this string be the binary content of calc.exe?</p>