Sometimes when doing the programming we have to find the file name from the given string. Classic ways we have to parse the file path and get the last array.
But in .NET Framework we have Path class and some built in method to find the filename from given file path
Path class is available in system.IO namespace.
below in the code to get the file name with extension.
Full Code in C#
string fileName = Path.GetFileName(@"C:\File Directory\fileName.txt");
Output will be
Hope this will help