I am adding event handler for CheckOutEventArgs, and am trying to get the checkout user details. Below is my code.
public void Subscribe()
{
EventSystem.Subscribe<Page, CheckOutEventArgs>(PageCheckOutWarning,
EventPhases.Initiated);
EventSystem.Subscribe<Component, CheckOutEventArgs>(ComponentCheckOutWarning,
EventPhases.Initiated);
}
private void ComponentCheckOutWarning(Component component,
CheckOutEventArgs args, EventPhases phase)
{
logdetails("Checkout User-->" + component.CheckOutUser.Title.ToString());
}
When I try to checkout the Component/Page I get this error in the Tridion Explorer error message box.
Object Reference not set to an instance of an object
You have subscribed to
Initiatedphase, in this phse item is not checked out yet, hence noCheckOutUser. You should subscribe to some of the later phases.Also, I don’t know what your code is doing, but you might consider subscribing to some generic class, like
VersionedItemthat contains both component and page.Again, not knowing your idea, but take a look at
SubscribeAsyncmethod if you want to have just warning. This way it will execute faster.If you still want to know the user in the initiated phase – you can get it from session:
component.Session.User.TitleYou can subscribe to VersionedItem and then in the event handler do:
Do you want to have just warning, or do you want to prevent CheckOut?