2012-05-25 100 views
0

我正在使用Asp.net Mvc3!File.Exist()返回错误的值

我写了下面的代码,以我的文件中搜索到该文件夹​​: -

string TrailorsPath =Server.MapPath("/ePortfolio/"+cid+"/Icons/"+ fileName); 
    if (System.IO.File.Exists(TrailorsPath)) 

但它总是给不正确的结果:

我的文件路径是这样的: -

"D:\SVN_HobbyHomes\HobbyHomesWebApp\ePortfolio\1\Icons" 
+0

什么值是'Server.MapPath(“/ ePortfolio /”+ cid +“/ Icons /”+ fileNa我)'回来? –

+0

我没有在您的示例路径中看到文件名,还放置了一个断点并查看cid和文件名的值 – Habib

回答

2

尝试在路径开始处使用“〜”。

string TrailorsPath =Server.MapPath("~/ePortfolio/"+cid+"/Icons/"+ fileName); 
0

可以有多个问题
将断点就行

string TrailorsPath =Server.MapPath("/ePortfolio/"+cid+"/Icons/"+ fileName); 

,并检查Server.MapPath("/ePortfolio/"+cid+"/Icons/"+ fileName)

的价值和利用开始这一

Server.MapPath("~/ePortfolio/"+cid+"/Icons/"+ fileName)