public void dgrListPDF_EditCommand(object source, DataListCommandEventArgs e) { int _ID = Convert.ToInt32(DataGrid_FilePDF.DataKeys[e.Item.ItemIndex].ToString()); Label lblUrl = (Label)e.Item.FindControl("lbFileAttach"); if (e.CommandArgument.ToString().ToLower() == "downloadfile") { string filePath = Server.MapPath("/" + System.Configuration.ConfigurationManager.AppSettings["viewimg"].ToString() + lblUrl.Text); if (File.Exists(filePath)) { Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + Path.GetFileName(lblUrl.Text)); Response.WriteFile(filePath); Response.Flush(); Response.End(); } else { FuncAlert.AlertJS(this, "File not found on server"); return; } } if (e.CommandArgument.ToString().ToLower() == "delete") { Daltinbai.Sp_DeleteT_Publish_Pdf(_ID); string path = HttpContext.Current.Server.MapPath("/" + System.Configuration.ConfigurationManager.AppSettings["viewimg"].ToString() + lblUrl.Text); System.IO.FileInfo fi = new System.IO.FileInfo(path); try { if (File.Exists(path)) { fi.Delete(); } } catch (Exception ex) { throw ex; } } LoadData_FilePDF(); }