title: StreamWriter writing to MemoryStream
body: <p>I was under the impression that when you called <code>Flush()</code> in a StreamWriter object it writes to the underlying stream, but apparently this isn't the case with my code. </p>
  
  <p>Instead of writing to my file it will just write nothing. Any ideas where I'm going wrong?</p>
  
  <pre><code>    public FileResult DownloadEntries(int id)
      {
          Competition competition = dataService.GetCompetition(id);
          IQueryable&lt;CompetitionEntry&gt; entries = dataService.GetAllCompetitionEntries().Where(e =&gt; e.CompetitionId == competition.CompetitionId);
  
          MemoryStream stream = new MemoryStream();
          StreamWriter csvWriter = new StreamWriter(stream, Encoding.UTF8);
  
          csvWriter.WriteLine("First name,Second name,E-mail address,Preferred contact number,UserId\r\n");
  
          foreach (CompetitionEntry entry in entries)
          {
              csvWriter.WriteLine(String.Format("{0},{1},{2},{3},{4}",
                  entry.User.FirstName,
                  entry.User.LastName,
                  entry.User.Email,
                  entry.User.PreferredContactNumber,
                  entry.User.Id));
          }
  
          csvWriter.Flush();
  
          return File(stream, "text/plain", "CompetitionEntries.csv");
      }
  </code></pre>