Wednesday, February 8, 2017

Using Event Receiver how to restrict the users to delete the documents in SharePoint Document library.

Solution:
First we have to create the event receiver using visual studio after that place the below code.Please modify the list title and error message and deploy the the event receiver from visual studio solution explorer.
        public override void ItemDeleting(SPItemEventProperties properties)
        {

            try
            {

                //base.ItemDeleting(properties);

                if (properties.ListTitle == "Sample Documents")
                {

                    properties.ErrorMessage = "You are not allowed to Delete the documents";

                    properties.Status = SPEventReceiverStatus.CancelWithError;

                    properties.Cancel = true;

                }

            }

            catch (Exception ex)
            {

                properties.Status = SPEventReceiverStatus.CancelWithError;

                properties.ErrorMessage = ex.Message.ToString();

                properties.Cancel = true;

                //throw;

            }

        }

No comments:

Post a Comment