//删除文件
    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;
            }
        }
    }错误 并非所有的代码路径都返回值?请教大家了~!谢谢

解决方案 »

  1.   

    如果for循环的条件不成立呢?
    所以在for外面加上return
      

  2.   

    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; 
                } 
            } 
            return true;
        } 
      

  3.   

    for 循环外加个return false