title: Easiest way to read from a URL into a string in .NET
body: <p>Given a URL in a string:</p>
  
  <pre><code>http://www.example.com/test.xml
  </code></pre>
  
  <p>What's the easiest/most succinct way to download the contents of the file from the server (pointed to by the url) into a string in C#?</p>
  
  <p>The way I'm doing it at the moment is:</p>
  
  <pre><code>WebRequest request = WebRequest.Create("http://www.example.com/test.xml");
  WebResponse response = request.GetResponse();
  Stream dataStream = response.GetResponseStream();
  StreamReader reader = new StreamReader(dataStream);
  string responseFromServer = reader.ReadToEnd();
  </code></pre>
  
  <p>That's a lot of code that could essentially be one line:</p>
  
  <pre><code>string responseFromServer = ????.GetStringFromUrl("http://www.example.com/test.xml");
  </code></pre>
  
  <p>Note: I'm not worried about asynchronous calls - this is not production code.</p>