System.IO.File.Exists()返回false [英] System.IO.File.Exists() returns false

查看:366
本文介绍了System.IO.File.Exists()返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我需要显示其存储在服务器上的图像。为了找到这个形象,我用下面的code:

I have a page where I need to display an image which is stored on the server. To find that image, I use the following code:

 if (System.IO.File.Exists(Server.MapPath(filepath)))

当我用这个,我得到一个正确的结果作为该文件是present。

When I use this, I get a proper result as the file is present.

但是,当我给一个绝对路径如下图所示:

But when I give an absolute path like below:

 if (System.IO.File.Exists("http://myserever.address/filepath"))

返回FALSE。

It returns false.

该文件在物理上是present有,但我不知道为什么它没有找到。

The file is physically present there, but I don't know why it's not found.

推荐答案

对于System.IO.File.Exists path参数是路径文件系统中的实际文件。

The path parameter for the System.IO.File.Exists is the path to an actual file in the file system.

要使用Server.Mappath()的调用更改URI到一个实际的文件路径。

The call to Server.MapPath() changes the URI into an actual file path.

所以它工作按预期。

这篇关于System.IO.File.Exists()返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆