kez kez - 1 year ago 131
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

I want to remove this
from above path and keep only

how can I do this easily

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download