title: How to rename a .txt document in c# using a name stacked in a string?
body: <p>So I'm making a desktop WPF app, whose main role is to create a .txt file with the content and name given by the user in 2 different TextBoxes(&quot;textHolder&quot; for the content and &quot;docName&quot; for the name).</p>
  <p>Basically, the user writes down a name for the document, some content and after he presses the &quot;Save&quot; button, the app creates a .txt document with those file infos. I managed to code the content and saving part, but I'm stuck tryning to change the name of the document.</p>
  <p>I've tried to change the name using the .MoveTo method but I can't figure out how to include the name given by the user in the string. (the following code doesn't work properly)</p>
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
  {
      StreamWriter sw = new StreamWriter(
          @&quot;C:\Users\alex_\OneDrive\All\Desktop\Texts\newTextDoc.txt&quot;);
  
      sw.Write(textHolder.Text);
      sw.Close();
  
      string nameOfTheDoc = docName.Text + &quot;.txt&quot;;
      string filePath = &quot;C:\\Users\\alex_\\OneDrive\\All\\Desktop\\Texts&quot;;
      string pathAndName = filePath + nameOfTheDoc;
  
      FileInfo fi = new FileInfo(
          @&quot;C:\Users\alex_\OneDrive\All\Desktop\Texts\newTextDoc.txt&quot;);
  
      if (fi.Exists)
      {
          fi.MoveTo(pathAndName);
      }
  } 
  </code></pre>