日期:2014-05-18  浏览次数:20495 次

关于File.Exists 和 File.Delete的问题,请教
string   TempPath   =   "D:\\wwwroot\\a.txt ";
if   (File.Exists(Server.MapPath(TempPath)))
{
  File.Delete(Server.MapPath(TempPath));
}

//无报错,但是无法删除
//测试用↓

string   TempPath   =   "D:\\wwwroot\\a.txt ";
aaa.Text   =   TempPath;
if   (File.Exists(Server.MapPath(TempPath)))
{
  File.Delete(Server.MapPath(TempPath));
  bbb.Text   =   TempPath;
}
ccc.Text   =   TempPath;

//aaa能取得值,bbb,ccc都没值!

//请教高手
//注:我权限已经EveryOne完全控制
//顺便问一下:支持IO操作的最低权限是什么啊??

------解决方案--------------------
try

去掉server.mappath

------解决方案--------------------
应该是路径问题  把路径改成项目根路径试试
------解决方案--------------------
Exists地用法好像不对!TRY IT
===================================
string TempPath = "D:\\wwwroot\\a.txt ";
FileInfo info=new FileInfo(TempPath);
if(info.Exists)
{
File.Delete(TempPath);
}
------解决方案--------------------
不用EVERYONE
只把ASPNET,NetWork Serivce,权限加上,应该就可以了