kez kez - 13 days ago 6
C# Question

Remove file path from "FilePathResult" keep only FileName.Extention

I have following code snippet

var fileResult = path as FilePathResult;


for above code snippet I'm getting long file path ,

Something like
D:\Projects\Upload_Images\A.jpeg


I want to remove this
D:\Projects\Upload_Images\
from above path and keep only
A.jpeg


how can I do this easily

Answer

Path.GetFileName will do the trick for you as it returns the file name and extension of the specified path string.

string fileName = @"D:\Projects\Upload_Images\A.jpeg";
string result = Path.GetFileName(fileName);
Comments