Moss document library-assign full control permissions to document creators

Source: Internet
Author: User
Today I am trying to write an eventhandler about the document library.

Requirement Source: users can create or upload documents in the document library, but cannot edit or delete them. Now they want to edit and delete their own documents.

I created a console application first.ProgramWhen this program is executed, it cyclically grants full control permissions to the creators of all files in the document library, and I will continue to complete the subsequent eventhandler, please help me to test whether such writing is feasible. Note that during the test, create a console application and copyCodeThen, replace the site URL with the actual URL, and the document library name with the actual document library name.

Program source code:

Using system;
Using system. Collections. Generic;
Using system. text;
Using Microsoft. SharePoint;

namespace testlistfolder {
class program {
static void main (string [] ARGs) {
spsecurity. codetorunelevated mycode = new spsecurity. codetorunelevated (testeven thandler);
spsecurity. runwithelevatedprivileges (mycode);
}

Public static void testeven thandler (){
Spsite site = new spsite (site URL );
Spweb web = site. rootweb; // the top-level website is opened.
Splist list = web. Lists [document library name];

For (Int J = 0; j <list. Items. Count; j ++ ){
Splistitem item = List. items [J];
Spfile file = List. Items. file;
Spuser user = file. Author;
Sproleassignment SA = new sproleassignment (spprincipal) User );
Sproledefinition role = web. roledefinitions ["Full Control"];
SA. roledefinitionbindings. Add (role );
Item. breakroleinheritance (true );
Item. roleassignments. Add (SA );
}
}
}
}
This is all the code of the console application, and pay attention to adding a reference to SharePoint

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.