Click to Rate and Give Feedback
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
This page is specific to
The 2007 product release

Other versions are also available for the following:
SPPermission Class (Microsoft.SharePoint)

Obsolete.  

Use the new SPRoleDefinition and SPRoleAssignment classes instead, to define roles and to assign users to them. For more information, see Changes in the Authorization Object Model. (In Windows SharePoint Services 2.0, SPRole represented the permission assigned to a user or group for a list or a site and is maintained for backward compatibility.)

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
<ObsoleteAttribute("Use the SPRoleAssignment class instead")> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
Public Class SPPermission
Visual Basic (Usage)
Dim instance As SPPermission
C#
[ObsoleteAttribute("Use the SPRoleAssignment class instead")] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
public class SPPermission

Use the Permissions property of either the SPList or SPWeb class to return an SPPermissionCollection object that represents the collection of permissions for a list or a site. Use an indexer to return a single permission from the collection. For example, if the collection is assigned to a variable named collPermissions, use collPermissions[index] in C#, or collPermissions(index) in Visual Basic, where index is either the index number of the permission in the collection or the SPMember object for a user or group that has the permission for the list or site.

A permission consists of a right or combination of rights as specified by the SPRights enumeration. The PermissionMask property contains the set of rights assigned to the user or group.

The following code example uses the PermissionMask property of the SPPermission class to modify the permissions assigned to a single user.

Visual Basic
Dim siteCollection As SPSite = SPContext.Current.Site
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim perms As SPPermissionCollection = list.Permissions
Dim users As SPUserCollection = site.Users

Dim member As SPMember = users("User_Name")

list.Permissions(member).PermissionMask = 
    SPRights.AddListItems Or SPRights.EditListItems
C#
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPPermissionCollection collPermissions = oList.Permissions;
    SPUserCollection collUsers = oWebsite.Users;

    SPMember oMember = collUsers["User_Name"];

    oList.Permissions[oMember].PermissionMask = 
        SPRights.AddListItems | SPRights.EditListItems;
}
NoteNote:

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

System.Object
  Microsoft.SharePoint.SPPermission
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker