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("textHolder" for the content and "docName" for the name).
Basically, the user writes down a name for the document, some content and after he presses the "Save" 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.
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)
private void Button_Click(object sender, RoutedEventArgs e)
{
StreamWriter sw = new StreamWriter(
@"C:\Users\alex_\OneDrive\All\Desktop\Texts\newTextDoc.txt");
sw.Write(textHolder.Text);
sw.Close();
string nameOfTheDoc = docName.Text + ".txt";
string filePath = "C:\\Users\\alex_\\OneDrive\\All\\Desktop\\Texts";
string pathAndName = filePath + nameOfTheDoc;
FileInfo fi = new FileInfo(
@"C:\Users\alex_\OneDrive\All\Desktop\Texts\newTextDoc.txt");
if (fi.Exists)
{
fi.MoveTo(pathAndName);
}
}