Archive for the 'Permissions' Category

15
Sep
08

The Unplugged SharePoint’s Object Model – RunWithElevatedPriveleges

I’m creating an project management portal in SharePoint through Object Model, The very basic but still its a great little method called “RunWithElevatedPriveleges” helps me to run all the premission issues “The Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges method that enables me to supply a delegate that runs a subset of code in the context of an account with higher privileges than the current user.”

not only do the subset of code more than that like this…

/// <summary>
///  The method to invoke and handle the ItemAdded Event for the Project's List.
/// </summary>
/// <param name="properties">'properties' context for ItemAdding Event handler</param>
public override void ItemAdded(SPItemEventProperties properties)
{
    ItemWorkspaceData itemWorkspaceData = this.GetItemWorkspaceData(properties);
 
    if (itemWorkspaceData.strAfterListItemWorkspaceUrl != string.Empty)
      {
           SPWeb itemWorkspace = new SPSite(itemWorkspaceData.strAfterListItemWorkspaceUrl).OpenWeb();
           Guid subGUID = itemWorkspace.ID;
     
                SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            this.ProcessItemWorkspacePermissions(subGUID, itemWorkspace, properties);
                       });
  
                itemWorkspace.Site.Dispose();
                itemWorkspace.Dispose();
                itemWorkspace = null;
            }
        }
}

/// <summary>
///  Sub Method to invoke the Project ItemWorkspace Permissions Settings...
/// </summary>
/// <param name="currentWeb">SPWeb, SpContext.Current.Web "current Web"</param>
/// <param name="strItemWorkSpaceUrl">String, sub Item WorkSpace server relative Url</param>
/// <param name="properties">'properties' context for respective event handler</param> 
private void ProcessItemWorkspacePermissions(Guid Id, SPWeb currentWeb, SPItemEventProperties properties)
{
    /// Adding the Project Item Workspace Permissions level Settings through Object model...
    /// This piece of code runs absoultly good with no premission issues...
}

Cheers !!! Happy Coding…




Calendar

June 2012
M T W T F S S
« Feb    
 123
45678910
11121314151617
18192021222324
252627282930  

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1 other follower


Follow

Get every new post delivered to your Inbox.