title: ASP.NET, Streamwriter, Filestream - 0 byte file
body: <p>This works:</p>
  
  <pre><code>using (StreamWriter stw = new StreamWriter(Server.MapPath("\\xml\\file.xml")))
  {
      stw.Write(xmlEncStr);
  }
  </code></pre>
  
  <p>This creates an empty file:</p>
  
  <pre><code>using (FileStream file = new FileStream(Server.MapPath("\\xml\\file.xml"), FileMode.CreateNew))
  {
      using (StreamWriter sw = new StreamWriter(file))
      {
          sw.Write(xmlEncStr);
      }
  }
  </code></pre>
  
  <p>I tried playing around with the FileStream constructor and tried flushing and I still get a zero byte file.  The string I am writing is a simple base64 encoded ascii string with no special characters.</p>
  
  <p>I know I can use the first example, but why won't the second work?</p>
  
  <p><strong>Update</strong></p>
  
  <p>This wasn't a Filestream/StreamWriter problem - it was a variable naming problem.  I corrected the code above, so now both versions work.  I originally had:</p>
  
  <pre><code>StreamWriter strw = new StreamWriter(file)
  </code></pre>