当前位置: 首页>>代码示例>>C#>>正文


C# Record.ToXml方法代码示例

本文整理汇总了C#中Record.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# Record.ToXml方法的具体用法?C# Record.ToXml怎么用?C# Record.ToXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Record的用法示例。


在下文中一共展示了Record.ToXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            MailAddress FromMailAddress;
            if (string.IsNullOrEmpty(this.FromEmail))
            {
                var settings = UmbracoConfig.For.UmbracoSettings();
                FromMailAddress = new MailAddress(settings.Content.NotificationEmailAddress);
            }
            else
            {
                string fromEmailField = this.FromEmail;
                string fromNameField = "";
                bool fromEmailFound = false;
                bool fromNameFound = false;

                try
                {

                    foreach (RecordField rf in record.RecordFields.Values)
                    {

                        string refinedCaption = "{" + rf.Field.Caption.ToLower().Replace(" ", "") + "}";
                        if (!fromEmailFound && refinedCaption == this.FromEmail.ToLower())
                        {
                            fromEmailField = rf.ValuesAsString();
                            fromEmailFound = true;
                        }
                        else if (!fromNameFound && !String.IsNullOrEmpty(this.FromName) && refinedCaption == this.FromName.ToLower())
                        {
                            fromNameField = rf.ValuesAsString();
                            fromNameFound = true;
                        }
                        //dont go any further to not waste time looking for something already there
                        if (fromEmailFound && fromNameFound)
                        {
                            break;
                        }
                    }
                    if (fromNameFound)
                    {
                        FromMailAddress = new MailAddress(fromEmailField, fromNameField);
                    }
                    else if (!string.IsNullOrEmpty(this.FromName))
                    {
                        FromMailAddress = new MailAddress(fromEmailField, this.FromName);
                    }
                    else
                    {
                        FromMailAddress = new MailAddress(fromEmailField);
                    }
                }
                catch (Exception ex)
                {
                    var settings = UmbracoConfig.For.UmbracoSettings();
                    FromMailAddress = new MailAddress(settings.Content.NotificationEmailAddress);
                }
            }
            var mailMessage = new MailMessage
            {
                From = FromMailAddress,
                Subject = this.Subject,
                ReplyTo = FromMailAddress,
                IsBodyHtml = true,
                BodyEncoding = Encoding.UTF8
            };

            if (this.Email.Contains(";"))
            {
                foreach (string email in this.Email.Split(';'))
                {
                    mailMessage.To.Add(email.Trim());
                }
            }
            else
            {
                mailMessage.To.Add(this.Email);
            }

            XmlNode xml = record.ToXml(new System.Xml.XmlDocument());

            // we will by default set the body to the record xml so if no xslt file is
            // present we atleast get the raw data.
            string result = xml.OuterXml;
            if (!string.IsNullOrEmpty(this.XsltFile))
            {
                result = XsltHelper.TransformXML(xml, this.XsltFile, null);
            }

            mailMessage.Body = "<p>" + Message + "</p><br />" + result;

            var smtpClient = new SmtpClient { EnableSsl = false };

            if (WebConfigurationManager.AppSettings.AllKeys.Contains("contourContribUseSsl") && WebConfigurationManager.AppSettings["contourContribUseSsl"].ToLower() == true.ToString().ToLower())
            {
                smtpClient.EnableSsl = true;
            }

            smtpClient.Send(mailMessage);

            return WorkflowExecutionStatus.Completed;
//.........这里部分代码省略.........
开发者ID:avatart0ph,项目名称:umbracoupgrade6to7,代码行数:101,代码来源:XSLTAndMessage.cs


注:本文中的Record.ToXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。