0

I'm creating publishing pages which are stored in "Pages Library". I want to know the status of that pages in PublishingEventReceiver. I had disabled approval status setting in page library. Becoz i don't want approval flow i user can directly publish that page.

There are three status of pages: 1. Checkout 2. Draft 3. Published

The problem is some times i am getting status as draft while publishing the page.

My Event Receiver:

 public override void ItemCheckedIn(SPItemEventProperties properties)
    {
        base.ItemCheckedIn(properties);

        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPListItem item = properties.ListItem;

                SPFile file = item.File;

                //SPFieldUserValue userValue = new SPFieldUserValue(properties.Web, item["StoryUser"].ToString());
                //SPUser userVal = userValue.User;
                //string Email = userVal.Email;
                //string name = userVal.Name;
                string email = item["EmailId"].ToString();
                string name = item["UserName"].ToString();
                Logger.WriteLog(Logger.Category.Information, "StoryPublishEvent", email);
                Logger.WriteLog(Logger.Category.Information, "StoryPublishEvent", file.Level.ToString());
                if (file.Level == SPFileLevel.Published)
                {
                    //send email
                }
            });
        }
        catch (Exception ex)
        {
            Logger.WriteLog(Logger.Category.Information, "ItemCheckedIn", ex.Message);
        }
    }
  • You can change the type of the even receiver from CheckedIn to ItemUpdated. – users1100 Jul 6 '15 at 4:47
  • if i change to ItemUpdated the event is not getting called.. – Rakesh Sadhula Jul 6 '15 at 4:48
  • now i'm able to call ItemUpdated event but it is calling multiple times even if i save or edit – Rakesh Sadhula Jul 6 '15 at 6:39
  • It is called by the SharePoint but here you will be able to get the exact publishing level of page. Is it working there though it is called multiple times? – users1100 Jul 6 '15 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.