Detect an item published in ItemUpdating eventReceiver
-
Tuesday, May 06, 2008 1:58 PMHi,
wondering on the web on this subject, I haven't found a lot of reference on detecting when ItemUpdating is called.
Finally I found a solution, even I would hardly call it a "solution", to understand when the Event Receiver ItemUpdating is called due to the publication of an item.
properties.AfterProperties["vti_draftOwnerId"] != null &&
properties.AfterProperties["vti_cachedcustomprops"] != null &&
properties.AfterProperties["vti_replid"] == null &&
properties.AfterProperties["vti_doclibmodstat"] != null)
If the condition is satisfied, it means that the update is a publish.
Now the question is: is there a better way to do it?
Please help!!!
Thanks,
Mauro
All Replies
-
Monday, May 12, 2008 2:50 PMPlease help

Mauro -
Monday, May 12, 2008 7:12 PM
you can check ModerationInformation in event handler to see if it is in published version or not. Approved is published. please check this as well. i have used it in ItemUpdated event to insert data to a Line of business application on publishing of a page. You can check it in ItemUpdating if it has the correct value as per your need otherwise use ItemUpdated in this case.
properties.ListItem.ModerationInformation==SPModerationStatusType.Approved
-
Thursday, May 15, 2008 4:46 PMHi,
in fact ModerationInformation should be the right thing to check but unfortunately it is meaningless in ItemUpdatING handler.
Checking it in Updated will not be able to cancel the pubishing event in case the logic behind triggers it.
Do you think there is another solution to this problem?
Mauro -
Thursday, May 15, 2008 7:23 PMUsually the requirement is if an item is published then send certain things to other system or sharepoint site etc. so you can acheive it in ItemUpdated event. What you get in ItemUpdating in ModerationInformation?
-
Friday, May 16, 2008 7:10 AMModeration Status is set to 'Pending'
Ther requirement in this workflow is to cancel the publish event if certains conditions (presence of a folder, files, mandatory fields) are not fulfilled. -
Wednesday, May 21, 2008 4:38 PM
Hi all,
Testing the solution once more, I figured out that it was still faulty in case the user rejects the submit for approval.
Here's the snippet that should do the trick
properties.AfterProperties["vti_draftOwnerId"] != null
&& properties.AfterProperties["vti_cachedcustomprops"] != null
&& properties.AfterProperties["vti_replid"] != null
&& properties.AfterProperties["vti_doclibmodstat"] != null
&& properties.AfterProperties["vti_doclibmodstat"] == 0
&& properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null
&& properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] == null
If you find any mistake\you gout a better idea, please tell...
Mauro -
Wednesday, August 19, 2009 11:25 AM
Hi,
Have you found a solution ?
Regards,
eric- Proposed As Answer by behin_thierry Thursday, March 11, 2010 10:31 AM
-
Thursday, March 11, 2010 10:38 AM
ok
I have to convert a docx to pdf when the item is approved, but if the conversion failed the approved must fail too,
and with your solution that works, I just change it a little :
public override void ItemUpdating(SPItemEventProperties properties) { base.ItemUpdating(properties); int resu = -1; if (properties.AfterProperties["vti_draftOwnerId"] != null && properties.AfterProperties["vti_replid"] != null && properties.AfterProperties["vti_doclibmodstat"] != null && Int32.TryParse(properties.AfterProperties["vti_doclibmodstat"].ToString(), out resu) && resu == 0 && properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] == null) { properties.ErrorMessage = "You approved the item"; properties.Cancel = true; } else { properties.ErrorMessage = "You didn't approve the item"; properties.Cancel = true; } }- Proposed As Answer by behin_thierry Thursday, March 11, 2010 10:39 AM
-
Friday, March 23, 2012 10:29 AM
If you are trying to detect an approval event in ItemUpdating I would do something like :
var moderationStatus = (SPModerationStatusType) properties.AfterProperties["vti_doclibmodstat"];
if (moderationStatus == SPModerationStatusType.Approved)
{
properties.Cancel = true;
properties.ErrorMessage = "STOP!!!";
}If you are tring to detect if an item has been approved. I would move the check to ItemUpdated and do a :
if (properties.ListItem.ModerationInformation.Status == SPModerationStatusType.Approved)
Industrial inspection cameras | Speed enforcement | Line scan cameras | Machine vision cameras
-
Friday, July 20, 2012 5:07 PM
Instead of using ItemUpdating, try using ItemUpdated. In that slightly later event you can just check if:
properties.ListItem.ModerationInformation==SPModerationStatusType.Approved
This thread is a little old but led me to a solution to a similar issue in SP2010.
- Proposed As Answer by James Hodges Friday, July 20, 2012 5:07 PM

