title: I cannot write text to a text file
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8698879/the-file-is-being-used-by-another-process-i-must-close-it-how">The file is being used by another process, I must close it? How?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm not sure why is that but I cannot write some data into text file. I am doing like so:</p>
  
  <pre><code>    private void CreateLastOpenFile()
      {
          if (!Directory.Exists(directory))
          {
              Directory.CreateDirectory(directory);
          }
  
          if (!File.Exists(file))
          {
              FileStream newFile = File.Create(file);
              newFile.Close();
          }
  
          using (StreamWriter lastOpenedFile = new StreamWriter(file))
          {
              lastOpenedFile.WriteLine(filePath);
          }
      }
  </code></pre>
  
  <p>Am I doing this correctly?Should I be checking if directory exists? If file exists? What's the proper way? I was using examples from MSDN but I'm not sure how to do this.</p>