protected void rptPublication_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "Delete": { string confirmValue = Request.Form["confirm_delete"]; if (confirmValue == "Oui") { int id = Convert.ToInt32(e.CommandArgument); Publication publication = pf.Get(id); pf.delete(id); try { string FileToDelete = Server.MapPath(publication.url); File.Delete(FileToDelete); } finally { Response.Redirect(Request.RawUrl); } } break; } case "Download": { int id = Convert.ToInt32(e.CommandArgument); Publication publication = pf.Get(id); if (File.Exists(Server.MapPath(publication.url))) { Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + publication.title + ".pdf"); Response.TransmitFile(Server.MapPath(publication.url)); Response.End(); } else { Response.Redirect(Request.RawUrl + "?erreur=True"); } break; } default: { break; } } }
public void Download_Click(object sender, EventArgs e) { Button btn = (Button)sender; if (btn.CommandName == "download") { int pubId = Int32.Parse(btn.CommandArgument.ToString()); Publication publication = pf.Get(pubId); string fileName = publication.title.Replace(" ", "_"); Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".pdf"); Response.TransmitFile(Server.MapPath(publication.url)); } }