User Group permissions for the list in SharePoint

Source: Internet
Author: User
Tags exit in

The purpose is to take advantage of the List permissions in Sharepoint. The records in the list are only accessible to the users of each user group based on their user group permissions.
1. After the list is added, set the list permission and delete all other user groups. Only the user groups you need are retained.
2. Use vs2005 to add a common class and reference c: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ ISAPI \ Microsoft. Sharepoint. dll. Inherits the spitemeventreceiver class and overwrites the addeditem method.

 

Public   Override   Void Itemadded (spitemeventproperties properties)
{
Spsecurity. runwithelevatedprivileges ( Delegate () // Use this method to simulate the Administrator account to run this event.Program
{
Using (Spsite site =   New Spsite (properties. siteid )) // If you use this method, you do not need to use dispose ().
{
Using (Spweb = Site. openweb (properties. openweb (). Id )) // Pay attention to the web method !!!
{
Try
{
Splist list = Web. Lists [properties. listid]; // Obtain the list of trigger events
// Get the list of trigger events
Splistitem item = List. Items. getitembyid (properties. listitemid );
// Cancel permission inheritance for this entry. If it is "false", all permissions will be removed, and only the system account will be retained. If it is "true", the upper-level permissions will be copied.
If ( ! Item. hasuniqueroleassignments)
{
Item. breakroleinheritance ( False );
}
// Permission Definition
Sproledefinition roledefinition = Web. roledefinitions. getbytype (sproletype. contributor );
// Obtain the user group
String Groupname = Isingroup (Web, properties. userloginname. Split ( ' : ' )[ 1 ]);
Writetxt (groupname + " AB " );
Spmember mem = Web. sitegroups [groupname];
Spprincipal sp = (Spprincipal) MEM;
Sproleassignment Ra =   New Sproleassignment (SP );
// Bind this role to a permission level
RA. roledefinitionbindings. Add (roledefinition );
// Bind the new permission to the List entry
Item. roleassignments. Add (RA );
Item. Update ();
}
Catch (exception ee)
{< br> writetxt (EE. tostring ();
}< BR >}< br>);
}

 

This class must be a key. Use the vs2005 command to generate an SNK file, and add it to the project file assemblyinfo. CS.
[Assembly: assemblydelaysign (false)] // whether to delay signature false: no delay signature true: delayed Signature
[Assembly: assemblykeyfile ("roadlist. SNK")] // path of the key file
Then generate the DLL file and use the gacutil/I file. dll command to add the DLL file to GAC.
 
Create a console program and reference c: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ ISAPI \ Microsoft. Sharepoint. dll.
 
Add and exit in the main program
// Obtain the website set object based on the URL of the website set
Spsite site = new spsite ("http: // sharepointsever: 60000 ");
Splist list = web. Lists ["list name"];
String asmname = "2000 eventhandler, version = 1.0.0.0, culture = neutral, publickeytoken = 79be99334218e9f4"; // Assembly name
String classname = "_ 000eventhandler. demoeventhandler"; // class name in the Assembly
List. eventreceivers. Add (speventreceivertype. itemadded, asmname, classname );
If no error occurs, the Custom Event is put in the current list. At this time, the user group can only access records in the user group.

Turn: http://blog.csdn.net/boy20000/archive/2008/04/24/2321266.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.