protected void Page_Load(object sender, EventArgs e) { this.RequirePermission(Affinity.RolePermission.AdminSystem); //this.Master.SetLayout("Administration Dashboard", MasterPage.LayoutStyle.ContentOnly); if (Request["a"].Equals("delete")) { Affinity.Attachment att = new Affinity.Attachment(this.phreezer); att.Load(int.Parse(Request["id"])); int orderId = att.Request.Order.Id; string fileName = att.Filepath; string filePath = Server.MapPath("./") + "attachments/" + fileName; try { File.Delete(filePath); log.Debug("Deleted attachment #" + att.Id + ": " + filePath); } catch (Exception ex) { log.Error("Unable attachment #" + att.Id + ": " + filePath); } att.Delete(); Affinity.UploadLogCriteria ulc = new Affinity.UploadLogCriteria(); ulc.AttachmentID = att.Id; ulc.OrderID = orderId; Affinity.UploadLogs uplogs = new Affinity.UploadLogs(this.phreezer); uplogs.Query(ulc); int cnt = uplogs.Count; for (int i = 0; i < cnt; i++) { Affinity.UploadLog ul = (Affinity.UploadLog)uplogs[i]; ul.Delete(); } //Affinity.UploadLogs ulc = new Affinity.UploadLogs(this.phreezer); this.Redirect("AdminOrder.aspx?id=" + orderId + "&feedback=Attachment+Deleted"); } else { this.Master.ShowFeedback("Unknown Action", MasterPage.FeedbackType.Error); } }
protected void Page_Load(object sender, EventArgs e) { // System.IO.Path.GetExtension(); Affinity.Attachment att = new Affinity.Attachment(this.phreezer); att.Load(NoNull.GetInt(Request["id"], 0)); if (!att.Request.Order.CanRead(this.GetAccount())) { Crash(302, "You do not have permission to view this attachment"); } string fileName = att.Filepath; string viewStyle = this.GetAccount().GetPreference("AttachmentBehavior", "attachment"); // inline || attachment string filePath = Server.MapPath("./") + "attachments/" + fileName.Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", "").Replace("", ""); FileInfo fi = new FileInfo(filePath); string contentType; // the viewstyle itself being inline/attachment would seem to be what we want // however it seems to be generally ignored by the browser. So, in addition // to setting that header, we will force the content type as well if (viewStyle.Equals("attachment")) { contentType = "application/octet-stream"; } else { switch (fi.Extension.Replace(".", "").ToLower()) { case "pdf": contentType = "application/pdf"; break; case "doc": contentType = "application/msword"; break; case "xls": contentType = "application/vnd.ms-excel"; break; case "tif": case "tiff": contentType = "image/tiff"; break; default: contentType = "application/octet-stream"; break; } } Response.Clear(); Response.ContentType = contentType; Response.AddHeader("content-length", fi.Length.ToString()); Response.AddHeader("Content-Disposition", "" + viewStyle + ";filename=\"" + fileName + "\""); Response.Buffer = true; Response.WriteFile(filePath); Response.End(); /* * // alternate way to write binary to the browser * byte[] data = pdf.GetData(); * Response.Clear(); * Response.ContentType = "application/pdf"; * Response.AddHeader("content-disposition", "inline;filename=FileName.pdf"); * Response.AddHeader("content-length", data.Length.ToString()); * Response.Buffer = true; * Response.BinaryWrite(data); * Response.End(); // this is required or else the pdf will open in a new window */ }