protected void DataList1_DeleteCommand(object sender, DataListCommandEventArgs e) { DownAttachBLL downbll3 = new DownAttachBLL();; string id = e.CommandArgument.ToString(); DownAttach downatt = new DownAttach(); downatt = downbll3.GetDownAttach(id); string filename = downatt.FileSaveName; //获得所要删除的文件名 if (downbll3.Delete(id)) { string url1 = "~/Attach/" + filename; string webFilePath1 = Server.MapPath(url1);//用来删除原有文件资料 System.IO.FileInfo file1 = new System.IO.FileInfo(webFilePath1); if (file1.Exists) { file1.Delete();//删除 } Response.Write("<script>alert('删除成功');</script>"); } this.Response.Redirect(this.Request.Url.ToString()); }
protected void Delete_Click(object sender, EventArgs e) { for (int i = 0; i < DataList1.Items.Count; i++) { if (((CheckBox)DataList1.Items[i].FindControl("selected")).Checked == true) { object s = ((System.Web.UI.WebControls.HyperLink)DataList1.Items[i].FindControl("Hyperlink0")).Text; DownAttachBLL downbll = new DownAttachBLL(); if (downbll.Delete(s)) { string filename = ((System.Web.UI.WebControls.Label)DataList1.Items[i].FindControl("filename")).Text; string url1 = "~/Attach/" + filename; string webFilePath1 = Server.MapPath(url1);//用来删除原有资料 System.IO.FileInfo file1 = new System.IO.FileInfo(webFilePath1); if (file1.Exists) { file1.Delete();//删除 } Response.Write("<script>alert('删除成功');history.back();</script>"); } } } this.Response.Redirect(this.Request.Url.ToString()); }