private void btnPostComment_Click(object sender, EventArgs e) { if (!IsValidComment()) { return; } if (news == null) { return; } //if (news.AllowCommentsForDays < 0) //{ // WebUtils.SetupRedirect(this, Request.RawUrl); // return; //} //DateTime endDate = news.StartDate.AddDays((double)news.AllowCommentsForDays); //if ((endDate < DateTime.UtcNow) && (news.AllowCommentsForDays > 0)) { return; } string attachFile1 = null; string attachFile2 = null; string attachmentsPath = NewsHelper.AttachmentsPath(siteSettings.SiteId, news.NewsID); if (uplAttachFile1.UploadedFiles.Count > 0 || uplAttachFile2.UploadedFiles.Count > 0) { try { string fileSystemPath = Server.MapPath(attachmentsPath); if (!Directory.Exists(fileSystemPath)) { Directory.CreateDirectory(fileSystemPath); } } catch (Exception ex) { } } if (uplAttachFile1.UploadedFiles.Count > 0) { if (SiteUtils.IsAllowedUploadBrowseFile(uplAttachFile1.UploadedFiles[0].GetExtension(), NewsConfiguration.JobApplyAttachFileExtensions)) { attachFile1 = uplAttachFile1.UploadedFiles[0].FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles); int i = 1; while (File.Exists(VirtualPathUtility.Combine(attachmentsPath, attachFile1))) { attachFile1 = i.ToInvariantString() + attachFile1; i += 1; } } } if (uplAttachFile2.UploadedFiles.Count > 0) { if (SiteUtils.IsAllowedUploadBrowseFile(uplAttachFile2.UploadedFiles[0].GetExtension(), NewsConfiguration.JobApplyAttachFileExtensions)) { attachFile2 = uplAttachFile2.UploadedFiles[0].FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles); int i = 1; while (File.Exists(VirtualPathUtility.Combine(attachmentsPath, attachFile2))) { attachFile2 = i.ToInvariantString() + attachFile2; i += 1; } } } News.AddNewsComment( news.NewsID, txtFullName.Text, txtPosition.Text, url, txtMessage.Text, txtAddress.Text, txtEmail.Text, txtPhone.Text, attachFile1, attachFile2, DateTime.UtcNow); if (!string.IsNullOrEmpty(attachFile1)) { string newAttachmentsPath = VirtualPathUtility.Combine(attachmentsPath, attachFile1); uplAttachFile1.UploadedFiles[0].SaveAs(Server.MapPath(newAttachmentsPath)); } if (!string.IsNullOrEmpty(attachFile2)) { string newAttachmentsPath = VirtualPathUtility.Combine(attachmentsPath, attachFile2); uplAttachFile2.UploadedFiles[0].SaveAs(Server.MapPath(newAttachmentsPath)); } try { StringBuilder message = new StringBuilder(); //message.Append(string.Format("<a target='_blank' href='{0}'>{1}</a>", url, url) + "<br /><br />"); if (!string.IsNullOrEmpty(txtPosition.Text.Trim())) { message.Append("<b>" + NewsResources.JobPositionLabel + ":</b> " + txtPosition.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtFullName.Text.Trim())) { message.Append("<b>" + NewsResources.JobFullNameLabel + ":</b> " + txtFullName.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtAddress.Text.Trim())) { message.Append("<b>" + NewsResources.JobAddressLabel + ":</b> " + txtAddress.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtEmail.Text.Trim())) { message.Append("<b>" + NewsResources.JobEmailLabel + ":</b> " + txtEmail.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(txtPhone.Text.Trim())) { message.Append("<b>" + NewsResources.JobPhoneLabel + ":</b> " + txtPhone.Text.Trim() + "<br />"); } if (!string.IsNullOrEmpty(attachFile1)) { string attachFile = string.Format("<a target='_blank' href='{0}'>{1}</a>", basePage.SiteRoot + Page.ResolveUrl(NewsHelper.AttachmentsPath(siteSettings.SiteId, newsId)) + attachFile1, attachFile1); message.Append("<b>" + NewsResources.JobAttachFile1Label + ":</b> " + attachFile + "<br />"); } if (!string.IsNullOrEmpty(attachFile2)) { string attachFile = string.Format("<a target='_blank' href='{0}'>{1}</a>", basePage.SiteRoot + Page.ResolveUrl(NewsHelper.AttachmentsPath(siteSettings.SiteId, newsId)) + attachFile2, attachFile2); message.Append("<b>" + NewsResources.JobAttachFile2Label + ":</b> " + attachFile + "<br />"); } message.Append("<b>" + NewsResources.JobMessageLabel + ":</b><br />" + SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteUtils.GetNavigationSiteRoot(), WebUtils.GetSiteRoot(), txtMessage.Text)); message.Append("<br /><br />"); EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "JobApplyNotification"); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } NewsHelper.SendCommentNotification( SiteUtils.GetSmtpSettings(), siteSettings.SiteGuid, fromAddress, fromAlias, template.ToAddresses, template.ReplyToAddress, template.CcAddresses, template.BccAddresses, template.Subject, template.HtmlBody, siteSettings.SiteName, message.ToString()); } catch (Exception ex) { log.Error("Error sending email from address was " + siteSettings.DefaultEmailFromAddress + " to address was " + siteSettings.CompanyPublicEmail, ex); } lblMessage.Text = MessageTemplate.GetMessage("JobApplyThankYouMessage", NewsResources.JobApplyThankYouLabel); pnlNewComment.Visible = false; }