After long time i came to know that item level security is not supported on document library as it is supported only on custom sharepoint list: refer below link to implement item level security on document library :
My project requirement was: Current logged in user can view all documents but delete only its own document and i have done it thru below programming for event handler where i have changed some of code as per my requirement.
Step 1: We will start by opening our Microsoft Visual Studio 2005 and create a new SharePoint Empty Project.
Step 2:Subsequently, we will add an Event Receiver item to our project. To do this right-click the project in the Solution Explorer > Add > New Item. In the Add new Item dialog box, select Event Receiver, name it CustomEvent, and then click Add. A Create Event Receiver dialog box will be displayed.
Stpe 3:Since we will customize a Document Library, select Document Library from the drop-down list in the Create Event Receiver dialog box, and then click Add. A CustomEvent folder with ItemEventReceiver.cs, ItemEventReceiver.xml, ListEventReceiver.cs, and ListEventReceiver.xml files will automatically be added to our project.
Step 4: Now it is time for us to write few lines of code. Let us open the ItemEventReceiver.cs file. Uncomment the ItemDeleting event, and then write the code below:
public override void ItemDeleting(SPItemEventProperties properties)
{
if (properties.ListTitle == “Custom Events”)
{
properties.ErrorMessage = “For demonstration purposes, deleting is not allowed.”;
properties.Cancel = true;
}
}
Step 5: To automate the deployment process, let us set the Start Action of our project. To do this, click Project > Project Name Properties. In the Project Properties page, select Debug tab. And in the Start Action section, select Start Browser with URL option, and then write http://sharepointking/
Step 6: Finally, let us build and deploy our project. To do this, click Build > Debug Project Name. If successful, click Build > Deploy Project Name.
Step 7: Upon successful deployment, let us open our SharePoint Web application, navigate to our Custom Events Document Library, add a document, then attempt to delete such document, and you would expect retention of the document with an error message
Recent Comments