Reputation: 535
HI,
I am trying to retrive the filname of the image file from a file path in my code.
My filepath: c:\mydocuments\pictures\image.jpg
which method can i use in c# to get he filename of the above mentioned path.
Like String file = image.jpg
I have used the system.drawing to get he path, but it returns null.
my code:
string file = System.drawing.image.fromfile(filepath,true);
Is this the right way to get the image file name or is there any other inbuilt method in c#.
Pls help me on this?
Upvotes: 0
Views: 12974
Reputation: 25277
System.IO.FileInfo info = new System.IO.FileInfo(filepath);
string fileName = info.Name;
Upvotes: 3
Reputation: 69242
Image.FromFile
returns an Image
object, not the filename.
If you just want to get the filename portion of a path, use System.IO.Path.GetFileName(path)
Upvotes: 0