【问题标题】:Get the image file path获取图片文件路径
【发布时间】:2010-05-20 06:01:37
【问题描述】:

嗨,

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

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

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

Like String file = image.jpg

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

我的代码:

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

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

请帮我解决这个问题?

【问题讨论】:

    标签: c# image filenames


    【解决方案1】:
    System.IO.FileInfo info = new System.IO.FileInfo(filepath);
    string fileName = info.Name;
    

    【讨论】:

    • 不应该是info.FullName吗?
    • @uriDium:不,OP 要求提供不带路径的文件名,在FileInfo 中,您将通过Name 属性获得它。
    【解决方案2】:

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 2013-08-12
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 2015-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多