title: Creating a Txt-File and write to it
body: <p>I want to create a text file then add the text of a <code>TextBox</code> to it.
  Creating the text file works without any problems with following code:</p>
  
  <pre><code>InitializeComponent();
  string path = @"C:\Users\Morris\Desktop\test.txt";
  if (!File.Exists(path))
  {
      File.Create(path);
  }
  </code></pre>
  
  <p>But I get an error that the file is being used when I try to add the text to the text file. If the file already exist before it run the code I don't get this error and the <code>TextBox.Text</code> is added to the File.
  I use this code to add the text to the text file:</p>
  
  <pre><code>public void writeTxt()
  {
      string path = @"C:\Users\Morris\Desktop\test.txt";
      if (File.Exists(path))
      {
          using (var tw = new StreamWriter(path, true))
          {
              tw.WriteLine(TextBox1.Text);
              tw.Close();
          }
      }
  }
  </code></pre>
  
  <p>Can you help me?</p>