开发者

Get the image file path

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?


System.IO.FileInfo info = new System.IO.FileInfo(filepath);
string fileName = info.Name;


Use Path.GetFileName


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜