title: FileStream writing buffer to file
body: <p>I'm trying to upload a .srt file through an API that takes File as a parameter.</p>
  
  <p>The file is stored on the server, and I'm using <code>FileStream</code> and <code>StreamWriter</code> to write to it:</p>
  
  <pre><code>string path = Server.MapPath("~/App_Data/captions/" + entryId) + ".srt";
  FileStream f = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  StreamWriter s = new StreamWriter(f);
  
  s.Write(someString);
  f.Flush()
  
  // Connecting to API and uploading the file
  
  s.Close();
  </code></pre>
  
  <p>However, even though the file is created correctly on my server, the uploaded file is empty. If the file already exists, it will upload that file correctly but only contain the existing content, and not the additional text I added from <code>someString</code>.</p>
  
  <p>I thought <code>f.Flush()</code> would ensure that the data in StreamWriter is written and saved to the file, but that doesn't seem to be the case. </p>
  
  <p>What do I have to do to make sure that the data is written to the file before it is uploaded through the API? </p>