Changing page item level permissions using event reciever
Changing item level permissions for pages library
In order to change item level permission as and when item added to a list or library, the best approach we follow is
- Writing event receiver for the list on ItemAdded
- Executing permission change block with elevated privileges.
But the same approach is not going to work on pages (publishing sites) library. The main reason for failing this approach is
- To change the permissions we have to execute permission block with elevated privileges. This block will run with system account user.
- When you are creating item with in the elevated privileges block, you will get item not found or index out of rang as the item is not available for other users.
- To make item available to other users, we can check in item with minor version with in the ItemAdded event receiver and then execute elevated block.
- If you are checking item with minor version and if the page template associated with any content type and there are any required fields then check in will fail.
This is not a bug or issue for publishing application. Pages which are checked in or published will be available for other users so when you are trying to identify an item in run with elevate privileges block , you are getting file not found or index out of rang.
To overcome this issue
- If content type associates to the page temple don’t have any required field then
- In the ItemAdded event receiver, check in the page with minor version
- Modify user permission with in the elevated block
- Checkout the item with the current user.
- If content type associated to the page template have required fields then
- Create ItemCheckedIn event receiver
- Make sure this event receiver code run only once.
- Modify user permission with in the elevated block.
- Train content authors to check-in the page with minor version after page created and updated required field.
Sample code block
if (!properties.ListItem.HasUniqueRoleAssignments){
SPSecurity.RunWithElevatedPrivileges(delegate() {
using (SPSite site = new SPSite(properties.WebUrl)){
using (SPWeb web = site.OpenWeb()){
SPListItem page = web.Lists[properties.ListId].GetItemById(properties.ListItem.ID);
page.BreakRoleInheritance(true);
}
}
}
}
October 12, 2012 - Posted by srinutamada | Event Reciever, SharePoint, SharePoint 2010, Technology | Item reciever, level permissions, Page library
No comments yet.
About
This is Srinu Tamada. Working as a Technology Lead for Infosys. I did MScIS from GITAM in 2004 and BCA from VSR-NVR Colleger in 2002. I came from a small village called Baipalli( Srikakulam district, andhra pradesh, India). My father worked as head master in ZPH School and mother is house wife. I have one elder sister and one elder brother. I am younger of my family.
Writing small telugu poems is one of my hobby. I spend my leasure time by reading different books especially I like to read RK Narayanan stories and ethics.
I am very interested in gathering techincal information also. Content that I published in my blog is not my own content. I gathered this information from various sites. Information that I had written with heading “Softwar Engineering” and “Scrum”, are my own content.
My best source for gathering information regarding .NET is “MSDN” and for software engineering concepts “Software Engineering by Pressman” book. Thanks to all the persons who helped me in writing my blog.
Categories
- A Brief Introduction to MVC model
- ABC of Cloud Computing
- ABC of Scrum
- Add-SPSolution Issue
- Advantage of VB.NET over VB
- Advantages of WCF
- Agile
- Architecture Design
- ASP.NET and WCF
- ASP.NET Configuration Settings
- ASP.NET Deployment
- ASP.NET MVC
- ASP.NET Presentation Patterns
- ASP.NET Web Parts Overview
- Assemblies
- Authentication in ASP.NET
- Backup of Deployed WSP
- Binary Serialization
- C#
- Ceiamerica Job Opening
- Client-Side Installation for COM+ Applications
- COM+ Security risks
- Connection Pooling in .NET
- Content Type level retention policy
- Creating Web Service for SharePoint
- Custom authentication to WCF service
- Custom Retention Policy
- DateDiff and DateAdd in C#
- Delegates
- Design
- Design Pattern
- Event Reciever
- Expression Blend
- Expression Web
- Framework
- Getting Lists
- IIS 6.0 Performance Tuning
- IIS 6.0 Security
- Installing COM+ Application Proxies
- Installing COM+ Applications
- Installing COM+ Server Applications
- Introduction to WCF
- Is MVC architecture a necessity?”
- Job Openings
- Memory Tracking
- MTS
- Named arguments
- New concepts in .NET 3.5
- Object Pooling in .NET
- Package Deployment
- Page Directives
- Performance Point Service
- Performance tips
- Power Shell
- Profiling
- Reading Summary Links
- Recycling in IIS
- Reflection
- Remoting
- Reset Custom Master Page
- Retention Policies
- Secure Coding Guidelines
- Serialization
- Service-oriented architecture
- SharePoint
- SharePoint 2010
- SharePoint 2010 Performance
- SharePoint 2013 Migration
- Silver light Layouts Part
- Silverlight Introduction
- Software Analysis
- Software Engineer
- State Management
- Technology
- Testing
- Uncategorized
- User Interface Design
- Versions
- web service
- What dynamic does NOT do
- Why Do We Need an Architect
- Why Silverlight Is Important?
- WPF and XAML Conventions
- XML Serialization
Posts Count By Month
- May 2016 (1)
- July 2013 (2)
- December 2012 (1)
- October 2012 (2)
- June 2012 (2)
- February 2012 (2)
- January 2012 (4)
- April 2011 (1)
- September 2010 (1)
- July 2010 (2)
- April 2010 (1)
- January 2010 (1)
- October 2009 (2)
- September 2009 (3)
- August 2009 (2)
- May 2009 (6)
- April 2009 (4)
- March 2009 (3)
- February 2009 (2)
- January 2009 (8)
- December 2008 (5)
- October 2008 (6)
- September 2008 (7)
- August 2008 (5)
- July 2008 (8)
-
Most Recent Posts
- Resetting master page using “Feature Upgrade” event
- SharePoint 2013 Content Migration Approach – Basics
- Listing all Sites and Webs having a List
- Content type level retention policy
- Reading Summary Links using Powershell
- Changing page item level permissions using event reciever
- SharePoint 2010 Performance – Improvement Steps
- SharePoint 2010 Performance – Identifying Pain Points
- Add-SPSolution Issue – SharePoint 2010
- Custom authentication to WCF service
Most Popular Posts
Leave a comment