读书人

(重新开一帖子 )图片是否存在?路过

发布时间: 2012-01-21 21:31:43 作者: rapoo

(重新开一帖子 )图片是否存在?路过的帮帮忙?
判断图片是否存在,我是这样写的:
public string GetPath(string name)
{
string pathweb = "~/CP/logo/"+name;
string pathadmin = "~/CorporationDirectory/logo/"+name;
string aa = "NoPhotos.jpg";
string pathdefault = "~/CorporationDirectory/logo/"+aa;
if (System.IO.File.Exists(pathweb))
{
return pathweb;
}
else if (System.IO.File.Exists(pathadmin))
{
return pathadmin;
}
else
{
return pathdefault;
}
}

但是为什么明明存在也是走else 呢???

帮帮忙。。。。。



[解决办法]
你判断的路径是不是写错了?
[解决办法]
System.IO.File.Exists(pathweb)-->System.IO.File.Exists(Server.MapPath(pathweb))

File.Exists要使用绝对路径,不能使用相对路径的
[解决办法]
pathweb = Server.MapPath(pathweb);
if(...){
}
[解决办法]
if (Directory.Exists(Server.MapPath(filename)))
[解决办法]
发表于:2007-10-18 10:22:403楼 得分:0
System.IO.File.Exists(pathweb)-- >System.IO.File.Exists(Server.MapPath(pathweb))

File.Exists要使用绝对路径,不能使用相对路径的


----------
正解

读书人网 >asp.net

热点推荐