获取图像文件路径

时间:2010-05-20 06:01:38

标签: c# image filenames

HI,

我正在尝试从代码中的文件路径中检索图像文件的filname。

我的文件路径:c:\ mydocuments \ pictures \ image.jpg

我可以在c#中使用哪种方法来获取上述路径的文件名。

喜欢String file = image.jpg

我已经使用system.drawing来获取路径,但它返回null。

我的代码:

string file = System.drawing.image.fromfile(filepath,true);

这是获取图像文件名的正确方法,还是c#中还有其他内置方法。

请帮我解决这个问题?

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

答案 2 :(得分:0)

Image.FromFile返回Image个对象,而不是文件名。

如果您只想获取路径的文件名部分,请使用System.IO.Path.GetFileName(path)

相关问题