当前位置: 代码迷 >> ASP.NET >> (重新开一帖子 )图片是否存在?路过的帮帮忙?解决方案
  详细解决方案

(重新开一帖子 )图片是否存在?路过的帮帮忙?解决方案

热度:4508   发布时间:2013-02-25 00:00:00.0
(重新开一帖子 )图片是否存在?路过的帮帮忙?
判断图片是否存在,我是这样写的: 
 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要使用绝对路径,不能使用相对路径的 
 
 
----------
正解
  相关解决方案