Umbraco: Execute Code after Document Publish in umbraco CMS by c#.

We often come across situations to execute some piece of code or call some function and store some value in data base or alert some java script function after saving document in umbraco. Find below code in below code we register Document.AfterPublish event at startup of Umbraco application and store some message in Log table of umbraco after document save.

Note make sure you have refer cms and interface and umbraco and businessLogic dll file while running below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.BusinessLogic;

namespace EventSamples
{
    public class TestEventHandle : umbraco.BusinessLogic.ApplicationBase
    {
        public TestEventHandle()
        {
            // Register AfterPublish event
            //Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);

        }

        /// <summary>
        /// Executes after document publishing
        /// </summary>
        /// <param name="sender">The sender (a documet 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)

            // Execute Some Logic Here.

            Log.Add(LogTypes.Save, sender.Id, "I am saving this message in umbraco Log Table");
        }
    }
}

For Working this just run it and take DLL File and save in umbraco bin folder and it will start working.

Another Umbraco Article

Page Keyword: Store Some value in database after document publish save in umbraco. Register document after publish event in umbraco at startup. Get and set some value after document publish in umbraco, Call function after document publish in umbraco, Add error message to Log tabel in umbraco. How to register event in umbraco. How to register Document AfterPublish event in Umbraco by c#.

Advertisements

One thought on “Umbraco: Execute Code after Document Publish in umbraco CMS by c#.

  1. Pingback: Create your first Rss Feed Burner in umbraco | [Code Destination]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s