private void SaveAttachment() { if (this.FileUpload1.HasFile == false) { PageCommon.WriteJsEnd(this, "Please select a valid file.", PageCommon.Js_RefreshSelf); } string sMsg = string.Empty; bool bValid = PageCommon.ValidateUpload(this, this.FileUpload1, 1024 * 1024 * 20, out sMsg, ".gif", ".jpg", ".jpeg", ".pdf", ".png", ".doc", ".docx", ".xls", ".xlsx", ".zip"); if (bValid == false) { PageCommon.WriteJsEnd(this, sMsg, PageCommon.Js_RefreshSelf); } string sSelEmailTemplateID = this.ddlEmailTemplate.SelectedValue; string sAttachName = this.txtAttchName.Text.Trim(); string sFileType = this.ddlFileType.SelectedValue; LPWeb.Model.Template_Email_Attachments AttachModel = new LPWeb.Model.Template_Email_Attachments(); AttachModel.TemplEmailId = Convert.ToInt32(sSelEmailTemplateID); AttachModel.Enabled = true; AttachModel.Name = sAttachName; AttachModel.FileType = sFileType; AttachModel.FileImage = this.FileUpload1.FileBytes; Template_Email_Attachments Template_Email_AttachmentsMgr = new Template_Email_Attachments(); Template_Email_AttachmentsMgr.Add(AttachModel); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["CloseDialogCodes"] != null) // 如果有LoanID { CloseDialogCodes = Request.QueryString["CloseDialogCodes"].ToString(); } if (Request.QueryString["TemplEmailId"] != null) // 如果有LoanID { string sTemplEmailId = Request.QueryString["TemplEmailId"]; if (PageCommon.IsID(sTemplEmailId) == false) { PageCommon.WriteJsEnd(this, sErrorMsg, CloseDialogCodes); } TemplEmailId = Convert.ToInt32(sTemplEmailId); } Token = Request.QueryString["token"] != null ? Request.QueryString["token"].ToString() : ""; isListTemplEmailAttach = Request.QueryString["isListTemplEmailAttach"] != null?Convert.ToBoolean(Request.QueryString["isListTemplEmailAttach"]) : false; if (!IsPostBack) { if (isListTemplEmailAttach) { LPWeb.BLL.Template_Email_Attachments bllTempEmailAttach = new Template_Email_Attachments(); var ds = bllTempEmailAttach.GetListWithOutFileImage(" Enabled =1 AND TemplEmailId = " + TemplEmailId); StringBuilder sb = new StringBuilder(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { sb.Append("<option value='s" + dr["TemplAttachId"].ToString() + "' >" + dr["Name"].ToString() + "." + dr["FileType"].ToString() + "</option>"); } } Default_lbxAttachments = sb.ToString(); } } ///判定是不是 在执行发送 if (Request.Form["hidIsSend"] != null) { sLocalTime = Request.Form["hfLocalTime"].ToString().Trim(); //Attachment #region Attachments if (Request.Files.Count > 0) { foreach (var key in Request.Files.AllKeys) { var file = Request.Files[key]; if (file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName)) { if (file.ContentLength > 1024 * 1024 * 20) { ErrorMsg("The file you tried to upload has exceeded the allowed limit, 20MB."); Response.End(); } byte[] bytes = new byte[file.InputStream.Length]; file.InputStream.Read(bytes, 0, bytes.Length); file.InputStream.Seek(0, SeekOrigin.Begin); FileInfo info = new FileInfo(file.FileName); Attachments.Add(info.Name, bytes); } } } #endregion if (Attachments.Count == 0) { ErrorMsg("Attachments / Note is empty."); Response.End(); } #region Save file try { LPWeb.BLL.Email_AttachmentsTemp bllEmailAttachTemp = new Email_AttachmentsTemp(); foreach (var item in Attachments) { LPWeb.Model.Email_AttachmentsTemp model = new LPWeb.Model.Email_AttachmentsTemp(); model.Token = Token; model.Name = item.Key.ToString().Substring(0, item.Key.ToString().LastIndexOf('.')); model.FileType = item.Key.ToString().Substring(item.Key.ToString().LastIndexOf('.') + 1); model.FileImage = item.Value; bllEmailAttachTemp.Add(model); } ErrorMsg(true, ""); } catch (Exception ex) { ErrorMsg(ex.Message.Replace("\"", "").Replace("\\n", "")); } #endregion Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { #region 校验页面参数 bool bValid = PageCommon.ValidateQueryString(this, "TemplAttachId", QueryStringType.ID); if (bValid == false) { this.Response.End(); } int TemplAttachId = Convert.ToInt32(this.Request.QueryString["TemplAttachId"]); #endregion #region 加载Email Template信息 Template_Email_Attachments Template_Email_AttachmentsMgr = new Template_Email_Attachments(); LPWeb.Model.Template_Email_Attachments AttchModel = Template_Email_AttachmentsMgr.GetModel(TemplAttachId); if (AttchModel == null) { PageCommon.WriteJsEnd(this, "Invalid email attachment id.", "window.close();"); } #endregion // 文件扩展名 string Ext = ""; if (AttchModel.FileType == "Word") { Ext = ".docx"; } else if (AttchModel.FileType == "XLS") { Ext = ".xlsx"; } else if (AttchModel.FileType == "JPGE") { Ext = ".jpg"; } else { Ext = "." + AttchModel.FileType.ToLower(); } // 文件名 string sFileName = AttchModel.Name + Ext; this.Response.Clear(); this.Response.ClearHeaders(); this.Response.Buffer = false; if (AttchModel.FileType == "PDF") { this.Response.ContentType = "application/pdf"; } else if (AttchModel.FileType == "Word") { this.Response.ContentType = "application/msword"; } else if (AttchModel.FileType == "XLS") { this.Response.ContentType = "application/vnd.ms-excel"; } else if (AttchModel.FileType == "ZIP") { this.Response.ContentType = "application/zip"; } else { this.Response.ContentType = "application/octet-stream"; } if (AttchModel.FileType == "ZIP" || AttchModel.FileType == "Word" || AttchModel.FileType == "XLS") { this.Response.AppendHeader("Content-Disposition", "attachment;filename=" + sFileName); } else { this.Response.AppendHeader("Content-Disposition", "inline;filename=" + sFileName); } this.Response.BinaryWrite(AttchModel.FileImage); this.Response.Flush(); //if (AttchModel.FileType == "Word" || AttchModel.FileType == "XLS" || AttchModel.FileType == "ZIP") //{ // PageCommon.WriteJsEnd(this, "", PageCommon.Js_CloseWindow); //} }