Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to be able to prevent the document in document library to be edited and it's properties updated when the custom document property DocState has a value Reviewed. Should I use document library event handlers? If yes, how?

Pseudo code

SPListItem document;
document = this.Web.Lists["Document Library Title"].GetItemById(x);
...
if (document["DocState"].ToString() == "Reviewed")
{
  // preventDocumentContentEditing!
  // preventDocumentPropertiesUpdating!
}

Thanks!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use SPItemEventReceiver to create your own event receiver. In your receiver you can implement ItemUpdating method. In this method you can retrieve item from SPItemEventProperties. Compare item field value with your value and use following code to cancel update:

properties.Cancel = true;
properties.ErrorMessage = "you can not update this item";
share|improve this answer
    
Great! Would that prevent both document content editing and properties updating? I am asking because I am not sure whether ItemUpdating would stop the user from opening the document in, say, Word and modify it's content. –  Boris Nov 29 '12 at 8:49
    
This event is handled when the user click Save Button. If you would like to prevent update action when the user opens an item, you can create custom edit form, on this form you can put a label with message and hide other controls. –  Alexander Nov 29 '12 at 8:59
    
So there is no property on the SPListItem or SPFile that I could use to make it read-only? –  Boris Nov 29 '12 at 9:05
1  
As I know you can set read only property to the document that is stored in the list by receiver... but I don't know how does it work with document metadata that are displayed in edit form. Also this approach is not applicable to the item of a list. –  Alexander Nov 29 '12 at 10:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.