See the following code:
string a = "C:\\example.txt";
string b = Path.GetFileName(a);
Then the value of
b
is "example.txt". Use
Path.GetFileNameWithoutExtension
to remove the extension also.
Note: Don't forget to add
using System.IO;
to use this code.