Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public override void ItemCheckingOut(SPItemEventProperties properties)
  2. {
  3. base.ItemCheckingOut(properties);
  4.  
  5. try
  6. {
  7. int currentUserId = properties.CurrentUserId;
  8.  
  9. // Get the currently running workflows on the list item.
  10. SPWorkflowCollection col = properties.Site.WorkflowManager.GetItemActiveWorkflows(properties.ListItem);
  11.  
  12. if (col.Count > 0)
  13. {
  14. foreach (SPWorkflow wf in col)
  15. {
  16. // If the workflow is one of the approvals (and therefore should be named as such),
  17. // and the initiator of the workflow (that's what the property AuthorUser is) doesn't match the current user,
  18. // prevent the user checking the item out.
  19. // If it does match, allow the checkout, as it's likely to be the workflow checking the item out.
  20. if ((properties.List.WorkflowAssociations[wf.AssociationId].Name.ToLower().Contains("approval")) && (wf.AuthorUser.ID != currentUserId))
  21. {
  22. // Need to cancel the checkout as the workflow is running and the document shouldn't be editable.
  23. properties.ErrorMessage = "The document is currently going through the Approval process. During this process, the document is not available for editing.";
  24. properties.Status = SPEventReceiverStatus.CancelWithError;
  25. }
  26. }
  27. }
  28. }
  29. catch (Exception ex)
  30. {
  31. properties.Status = SPEventReceiverStatus.CancelWithError;
  32. properties.ErrorMessage = ex.Message;
  33. return;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement