//删除文件
protected bool deleteFile(purvey dbpurvey)
{
ad = dbpurvey.purveyimges(dbpurvey);
for (int i = 0; i < ad.Rows.Count; i++)
{
string filename = ad.Rows[i]["imname"].ToString();
string path = Server.MapPath("../../proscenium/userAdmin/pic/") + filename;//定义文件位置。
if (System.IO.File.Exists(path))//文件是否存在
{
try
{
System.IO.File.Delete(path);
return true;
}
catch (Exception)
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("删除失败!"));
return false;
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("该图片不存在!!"));
return false;
}
}
}错误 并非所有的代码路径都返回值?请教大家了~!谢谢
protected bool deleteFile(purvey dbpurvey)
{
ad = dbpurvey.purveyimges(dbpurvey);
for (int i = 0; i < ad.Rows.Count; i++)
{
string filename = ad.Rows[i]["imname"].ToString();
string path = Server.MapPath("../../proscenium/userAdmin/pic/") + filename;//定义文件位置。
if (System.IO.File.Exists(path))//文件是否存在
{
try
{
System.IO.File.Delete(path);
return true;
}
catch (Exception)
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("删除失败!"));
return false;
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("该图片不存在!!"));
return false;
}
}
}错误 并非所有的代码路径都返回值?请教大家了~!谢谢
所以在for外面加上return
{
ad = dbpurvey.purveyimges(dbpurvey);
for (int i = 0; i < ad.Rows.Count; i++)
{
string filename = ad.Rows[i]["imname"].ToString();
string path = Server.MapPath("../../proscenium/userAdmin/pic/") + filename;//定义文件位置。
if (System.IO.File.Exists(path))//文件是否存在
{
try
{
System.IO.File.Delete(path);
return true;
}
catch (Exception)
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("删除失败!"));
return false;
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(GetType(), "erre", Message.MessageBox("该图片不存在!!"));
return false;
}
}
return true;
}