title: Convert MemoryStream to FileStream creates hundreds of identical files?
body: <p>I am accessing a httpwebrequest that returns a pdf file as the response. I am reading that response into a memory stream, and later on converting to a file. The problem is, is that hundreds of files are being created. Not sure why, I've tried many ways, and all do the same...
  This is the first method which returns the memorystream.</p>
  
  <pre><code>        MemoryStream memStream = new MemoryStream();
          byte[] buffer = new byte[2048];
  
          int bytesRead = 0;
          do
          {
              bytesRead = _ResponseStream.Read(buffer, 0, buffer.Length);
              memStream.Write(buffer, 0, bytesRead);
          } while (bytesRead != 0);
  </code></pre>
  
  <p>Second to convert to FileStream...</p>
  
  <pre><code>            byte[] data = stream.ToArray();
  
              FileStream fs = new FileStream(newFile, FileMode.CreateNew);
              fs.Write(data, 0, data.Length);
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT TO ADD MORE CODE...</strong></p>
  
  <pre><code>    public MemoryStream GetToStream()
      {
          if (_Req == null)
              throw new Exception("HttpWebRequest is not initialised");
  
          GetResult(_Req);
  
          MemoryStream memStream = new MemoryStream();
          byte[] buffer = new byte[2048];
  
          int bytesRead = 0;
          do
          {
              bytesRead = _ResponseStream.Read(buffer, 0, buffer.Length);
              memStream.Write(buffer, 0, bytesRead);
          } while (bytesRead != 0);
  
          _ResponseStream.Close();
  
          if (memStream.Length &gt; 0)
              return memStream;
          else return null;
      }
  </code></pre>
  
  <p>newFile is the mapped path to the server of the file to create.</p>
  
  <pre><code>            byte[] data = stream.ToArray();
  
              FileStream fs = new FileStream(newFile, FileMode.Create);
              fs.Write(data, 0, data.Length);
              fs.Close();
  </code></pre>
  
  <p>I've tried stream.WriteTo(fs), and same thing occurs. Quite bizzare.</p>