删除根目录(文件夹里的)图片

  public string delimge(string AttachmentID, string fileUrl)
        {
            string connstrs = ""; try { connstrs = this.Request.Headers["ProjectType"].ToString(); }
            catch (Exception e) { connstrs = "SqlConnectionStr"; }
            try
            {
                var Purl = fileUrl.Replace("http://192.***.*.***/Api", "");


                //删除根目录图片(单张)

                string file = System.Web.HttpContext.Current.Server.MapPath("../" + Purl);
                file = file.Replace(",", "");
                if (System.IO.File.Exists(file))
                {
                    System.IO.File.Delete(file); ;

                }
                string sql = "";
                sql += "delete Attachment where AttachmentID=" + AttachmentID;
                var num = SqlHelper.ExecuteNonQuery(sql.ToString(), connstrs);
                return format.ResultJsonData("SUCCESS", "删除信息成功!", num);
            }
            catch (Exception ex)
            {

                return format.ResultJsonData("FAILED", "删除失败!", 0);
            }

        }

 

posted @ 2023-09-14 15:24  3939!  阅读(25)  评论(0编辑  收藏  举报