How do I output the name of the file?

Want to display in a textbox the name of the file, but displays its location.
Here is my code:
OpenFileDialog ofd = new OpenFileDialog();
 ofd.DefaultExt = "fb2";
 ofd.Filter = "fb2 files (*.fb2)|*.fb2|All files (*.*)|*.*";

 Nullable<bool> result = ofd.ShowDialog();
 if (result.HasValue == true)
{
 // Open document 
 string filename = ofd.FileName;
 tittle_tb.Text = filename;
 }
April 3rd 20 at 18:30
1 answer
April 3rd 20 at 18:32
Solution
Use Path.GetFileName

if (result.HasValue == true)
{
 // Open document 
 string filename = ofd.FileName;
 tittle_tb.Text = Path.GetFileName(filename);
}
And could you help, please? I need the selected file is moved to a different folder? How to apply to the selected file? - elsa25 commented on April 3rd 20 at 18:35
@elsa25, use File.Replace
You already have the original path to the file (string filename = ofd.FileName), so just specify the new path where you want to move.
string filename = ofd.FileName;
tittle_tb.Text = Path.GetFileName(filename);
replaceDirectory string = @"C:\";
File.Replace(filename, $"{replaceDirectory}{tittle_tb.Text}");
- Amparo89 commented on April 3rd 20 at 18:38

Find more questions by tags WPFC#