Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override void ItemCheckingOut(SPItemEventProperties properties)
- {
- base.ItemCheckingOut(properties);
- try
- {
- int currentUserId = properties.CurrentUserId;
- // Get the currently running workflows on the list item.
- SPWorkflowCollection col = properties.Site.WorkflowManager.GetItemActiveWorkflows(properties.ListItem);
- if (col.Count > 0)
- {
- foreach (SPWorkflow wf in col)
- {
- // If the workflow is one of the approvals (and therefore should be named as such),
- // and the initiator of the workflow (that's what the property AuthorUser is) doesn't match the current user,
- // prevent the user checking the item out.
- // If it does match, allow the checkout, as it's likely to be the workflow checking the item out.
- if ((properties.List.WorkflowAssociations[wf.AssociationId].Name.ToLower().Contains("approval")) && (wf.AuthorUser.ID != currentUserId))
- {
- // Need to cancel the checkout as the workflow is running and the document shouldn't be editable.
- properties.ErrorMessage = "The document is currently going through the Approval process. During this process, the document is not available for editing.";
- properties.Status = SPEventReceiverStatus.CancelWithError;
- }
- }
- }
- }
- catch (Exception ex)
- {
- properties.Status = SPEventReceiverStatus.CancelWithError;
- properties.ErrorMessage = ex.Message;
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement