title: Returning a stream from File.OpenRead()
body: <p>I'm in the process of writing a WCF service that will allow an ASP.Net web site to retrieve files (based on <a href="http://msdn.microsoft.com/en-us/library/ms789010.aspx#Y912">this article</a>). My problem is that when I return the stream, it's blank.</p>
  
  <p>For simplicity, I've isolated the code into a simple winforms app to try and find what the problem is with returning a stream and this is the code: </p>
  
  <pre><code>    private Stream TestStream()
      {
          Stream fs = File.OpenRead(@"c:\testdocument.docx");
          return fs;
      }
  
      // This method converts the filestream into a byte array so that when it is 
      // used in my ASP.Net project the file can be sent using response.Write
      private void Test()
      {            
          System.IO.MemoryStream data = new System.IO.MemoryStream();
          System.IO.Stream str = TestStream();
  
          str.CopyTo(data);
          byte[] buf = new byte[data.Length];
          data.Read(buf, 0, buf.Length);                       
      }
  </code></pre>
  
  <p>The result of this code is that <code>buf</code> is 12,587 bytes long (the correct length of the file) but it just contains 0's.</p>
  
  <p>The Word document opens without problems if I try it, am I missing something obvious?</p>