Exemplo n.º 1
0
        /// <summary>
        ///     Function to email error messages
        /// </summary>
        /// <param name="errSysMsg"></param>
        public bool logErrorEmail(string APP_NAME, Exception errSysMsg, string errTitle)
        {
            try
            {
                string EmailTo  = spHelper.GetRCRSettingsItem("EmailTo").ToString();
                string strError = System.DateTime.Now + "<br>Application: " + APP_NAME + "<br>Error Message: " + errSysMsg.Message + "<br>";

                //Check the InnerException
                while ((errSysMsg.InnerException != null))
                {
                    strError += errSysMsg.InnerException.ToString();
                    errSysMsg = errSysMsg.InnerException;
                }

                //Send error log via email
                SPUtility.SendEmail(SPContext.Current.Web, false, false, EmailTo, errTitle, strError);

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, strError, errSysMsg.StackTrace);
                return(true);
            }
            catch
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, errSysMsg.Message.ToString(), errSysMsg.StackTrace);
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Convert document to PDF
        /// </summary>
        public void ConvertDocToPDF(SPListItem listItem)
        {
            try
            {
                SharePointHelper spHelper    = new SharePointHelper();
                string           WordAutoSvc = spHelper.GetRCRSettingsItem("AutomationServices").ToString();

                //Variables used for PDF conversions
                ConversionJobSettings jobSettings;
                ConversionJob         pdfConversionJob;
                string wordFile; //Source Word file
                string pdfFile;  //target destination PDF file

                // Initialize the conversion settings.
                jobSettings = new ConversionJobSettings();
                jobSettings.OutputFormat = SaveFormat.PDF;

                // Create the conversion job using the settings.
                pdfConversionJob = new ConversionJob(WordAutoSvc, jobSettings);

                //Set the credentials to use when running the conversion job.
                pdfConversionJob.UserToken = SPContext.Current.Web.CurrentUser.UserToken;

                // Set the file names to use for the source Word document and the destination PDF document.
                wordFile = SPContext.Current.Web.Url + "/" + listItem.Url;
                if (IsFileTypeDoc(listItem.File, "docx"))
                {
                    pdfFile = wordFile.Replace(".docx", ".pdf");
                }
                else if (IsFileTypeDoc(listItem.File, "doc"))
                {
                    pdfFile = wordFile.Replace(".doc", ".pdf");
                }
                else
                {
                    pdfFile = "";
                }

                if (pdfFile.Length > 0)
                {
                    // Add the file conversion to the conversion job.
                    pdfConversionJob.AddFile(wordFile, pdfFile);

                    // Add the conversion job to the Word Automation Services conversion job queue.
                    // The conversion does not occurimmediately but is processed during the next run of the document conversion job.
                    pdfConversionJob.Start();
                }

                spHelper = null;
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ClassName, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "ConvertDocToPDF - " + ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Function to email system error messages
        /// </summary>
        /// <param name="errSysMsg"></param>
        public bool sendUserEmail(string APP_NAME, string Title, string emailBody, bool isHTMLFormat)
        {
            try
            {
                string           categorySetting = "EmailTo";
                SharePointHelper spHelper        = new SharePointHelper(_spSettingList, categorySetting, _spCurrentWeb);
                string           EmailTo         = spHelper.GetRCRSettingsItem(categorySetting, _spSettingList).ToString();

                //Send error log via email
                SPUtility.SendEmail(_spCurrentWeb, isHTMLFormat, false, EmailTo, Title, emailBody);
                spHelper = null;

                return(true);
            }
            catch (Exception errSysMsg)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, errSysMsg.Message.ToString(), errSysMsg.StackTrace);
                return(false);
            }
        }
        /// <summary>
        ///     Workflow activity to send email to end users after completing pdf conversion workflow activity
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sendUserEmail_MethodInvoking(object sender, EventArgs e)
        {
            string docFileName = workflowProperties.WebUrl + "/" + workflowProperties.ItemUrl;
            string pdfFileName = Path.ChangeExtension(docFileName, "pdf");
            string itemID      = workflowProperties.Item.ID.ToString();
            string spSiteUrl   = SPContext.Current.Site.Url;

            try
            {
                using (SPWeb spWeb = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl))
                {
                    SharePointHelper objSPHelper = new SharePointHelper(PDF_SETTING_LIST, "EmailTo", spWeb);
                    SPFieldUserValue currentUser = objSPHelper.GetCurrentUser(spWeb);
                    StringBuilder    emailBody   = new StringBuilder();

                    emailBody.Append("Dear " + currentUser.User.Name + ",<br>");
                    emailBody.Append("<p>The document " + docFileName + " is in the process for PDF conversion. Please wait for the PDF file link below to be made availiable.</p><p><b>PDF file:</b> " + pdfFileName + "</p>");

                    sendEmail_From1    = objSPHelper.GetRCRSettingsItem("EmailFrom", PDF_SETTING_LIST);
                    sendEmail_Subject1 = "PDF Conversion Notification";
                    sendEmail_To1      = currentUser.User.Email;
                    Email_Body1        = emailBody.ToString();

                    WriteWFLog("PDF Notification Email", "Email has been successfully sent to " + currentUser.User.Email, spSiteUrl, docFileName, pdfFileName, itemID, true);
                    objSPHelper = null;
                    currentUser = null;
                }
            }
            catch (Exception err)
            {
                SPWeb          spCurrentWeb = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl);
                LogErrorHelper objErr       = new LogErrorHelper(PDF_SETTING_LIST, spCurrentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at sendUserEmail_MethodInvoking function");
                objErr       = null;
                spCurrentWeb = null;

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace);
                WriteWFLog("ERROR sending email to user!", err.Message.ToString(), spSiteUrl, docFileName, "", itemID, false);
            }
        }
        /// <summary>
        ///    Email user using custom SMTP server
        /// </summary>
        /// <param name="APP_NAME"></param>
        /// <param name="errSysMsg"></param>
        /// <param name="errTitle"></param>
        /// <returns>Returns true if email was sucessfully sent</returns>
        private bool SendUserEmail(string emailBody, string Title, bool isHTMLFormat)
        {
            try
            {
                string EmailTo = string.Empty;

                using (SPWeb spWeb = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl))
                {
                    SharePointHelper spHelper    = new SharePointHelper(PDF_SETTING_LIST, "EmailTo", spWeb);
                    SPFieldUserValue currentUser = spHelper.GetCurrentUser(spWeb);
                    EmailTo     = currentUser.User.Email;
                    currentUser = null;

                    string EmailFrom     = spHelper.GetRCRSettingsItem("EmailFrom", PDF_SETTING_LIST).ToString();
                    string SMPTServer    = spHelper.GetRCRSettingsItem("SMTPServer", PDF_SETTING_LIST).ToString();
                    string useProxyEmail = spHelper.GetRCRSettingsItem("UseProxyEmail", PDF_SETTING_LIST).ToString();


                    //Send error log via email
                    MailMessage message = new MailMessage();
                    message.From = new MailAddress(EmailFrom);

                    if (isHTMLFormat)
                    {
                        message.IsBodyHtml = true;
                    }

                    message.ReplyTo = new MailAddress(EmailFrom);
                    message.Sender  = new MailAddress(EmailFrom);

                    message.To.Add(new MailAddress(EmailTo));
                    // message.CC.Add(new MailAddress("*****@*****.**"));
                    message.Subject = Title;
                    message.Body    = emailBody;

                    SmtpClient client = new SmtpClient();
                    client.Host = SMPTServer;

                    if (useProxyEmail == "true")
                    {
                        client.UseDefaultCredentials = true;
                        string Domain          = spHelper.GetRCRSettingsItem("Domain", PDF_SETTING_LIST).ToString();
                        string SysAcct         = spHelper.GetRCRSettingsItem("ProxyUser", PDF_SETTING_LIST).ToString();
                        string SysAcctPassword = spHelper.GetRCRSettingsItem("ProxyPassword", PDF_SETTING_LIST).ToString();

                        client.Credentials = new System.Net.NetworkCredential(Domain + "\\" + SysAcct, SysAcctPassword);
                    }

                    client.Send(message);
                    spHelper = null;
                }
                return(true);
            }
            catch (Exception err)
            {
                SPWeb          spCurrentWeb = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl);
                LogErrorHelper objErr       = new LogErrorHelper(PDF_SETTING_LIST, spCurrentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at SendUserEmail function");
                objErr       = null;
                spCurrentWeb = null;

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace);

                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///    Email and log error message using custom SMTP server
        /// </summary>
        /// <param name="APP_NAME"></param>
        /// <param name="errSysMsg"></param>
        /// <param name="errTitle"></param>
        /// <returns>Returns true if email was sucessfully sent</returns>
        public bool logErrorSMTPEmail(string APP_NAME, Exception errSysMsg, string errTitle, bool isHTMLFormat)
        {
            try
            {
                SharePointHelper spHelper = new SharePointHelper(_spSettingList, "", _spCurrentWeb);

                string EmailTo       = spHelper.GetRCRSettingsItem("EmailTo", _spSettingList).ToString();
                string EmailFrom     = spHelper.GetRCRSettingsItem("EmailFrom", _spSettingList).ToString();
                string SMPTServer    = spHelper.GetRCRSettingsItem("SMTPServer", _spSettingList).ToString();
                string useProxyEmail = spHelper.GetRCRSettingsItem("UseProxyEmail", _spSettingList).ToString();

                string strError = System.DateTime.Now + "<br>Application: " + APP_NAME + "<br>Error Message: " + errSysMsg.Message + "<br>";

                //Check the InnerException
                while ((errSysMsg.InnerException != null))
                {
                    strError += errSysMsg.InnerException.ToString();
                    errSysMsg = errSysMsg.InnerException;
                }

                //Send error log via email
                MailMessage message = new MailMessage();
                message.From = new MailAddress(EmailFrom);

                if (isHTMLFormat)
                {
                    message.IsBodyHtml = true;
                }

                message.ReplyTo = new MailAddress(EmailFrom);
                message.Sender  = new MailAddress(EmailFrom);

                message.To.Add(new MailAddress(EmailTo));
                // message.CC.Add(new MailAddress("*****@*****.**"));
                message.Subject = errTitle;
                message.Body    = strError;

                SmtpClient client = new SmtpClient();
                client.Host = SMPTServer;

                if (useProxyEmail == "true")
                {
                    client.UseDefaultCredentials = true;
                    string Domain          = spHelper.GetRCRSettingsItem("Domain", _spSettingList).ToString();
                    string SysAcct         = spHelper.GetRCRSettingsItem("ProxyUser", _spSettingList).ToString();
                    string SysAcctPassword = spHelper.GetRCRSettingsItem("ProxyPassword", _spSettingList).ToString();

                    client.Credentials = new System.Net.NetworkCredential(Domain + "\\" + SysAcct, SysAcctPassword);
                }

                client.Send(message);
                spHelper = null;

                return(true);
            }
            catch
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, errSysMsg.Message.ToString(), errSysMsg.StackTrace);
                return(false);
            }
        }