Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael 125 posts 409 karma points
    Jun 04, 2015 @ 14:24
    Michael
    0

    CopyDocumentToRelatedOnPublish

    Hi Tim,

    Can you please update you code to avoid obsolete methods.

    using System;

    using System.Collections.Generic;

    using System.Text;

     

    using umbraco.BusinessLogic;

    using umbraco.cms.businesslogic.web;

    using umbraco.cms.businesslogic.relation;

    using umbraco.cms.businesslogic.property;

    using umbraco.cms.businesslogic;

     

    namespace Goyaweb.MultiLanguage

    {

     

        // code by Tim Geyssens

        public class CopyDocumentToRelatedOnPublish : ApplicationBase

        {

            //Constructor

            public CopyDocumentToRelatedOnPublish()

            {

                //subscribe to the afterpublish events

                Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);

            }

     

            /// <summary>

            /// Executes after document publishing

            /// </summary>

            /// <param name="sender">The sender (a document object).</param>

            /// <param name="e">The <see cref="umbraco.cms.businesslogic.PublishEventArgs"/> instance containing the event data.</param>

            void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)

            {

                // if the parent doesn't already have been related

                bool hasCopy = false;

                if (sender.Relations.Length > 0 && sender.Level > 1)

                {

                    foreach (Relation r in sender.Parent.Relations)

                    {

                        if (r.RelType.Alias == "relateDocumentOnCopy")

                        {

                            hasCopy = true;

                            break;

                        }

                    }

                }

     

                // if the parent documentObject have a relation

                if (!hasCopy && sender.Level > 1)

                {

                    Document parent = new Document(sender.Parent.Id);

                    if (parent.Relations.Length > 0)

                    {

                        foreach (Relation r in parent.Relations)

                        {

                            if (r.RelType.Alias == "relateDocumentOnCopy")

                            {

                                sender.Copy(r.Child.Id, sender.User, true);

                            }

                        }

                    }

                }

     

            }

        }

     

    }

     

     I have some troubles to do this.

    Thanks,

    Mike

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies