SharePoint adds permissions to each data entry in the Document Library

Source: Internet
Author: User
Preface

The boss task is to read every piece of data in the document library and add permissions. It's quite easy, but it's quite easy to do, haha. I have never touched on these codes, so I have to keep asking. I understood the big question and implemented it briefly. The application console first made some simple functions, which included dead but completely writable.

Code Section

// Read the website set

Spsite site = new spsite ("http: // localhost"); spwebapplication webapp = site. webapplication; spweb = site. openweb (); // used to update the web in the document library. allowunsafeupdates = true; // splist doclib = NULL in the Document Library; try {// here the file library is read and written to the dead doclib = web. lists ["mydocument"];} catch (exception) {console. writeline ("no? Right? "); Return;} sproleassignment roleassignment = NULL; If (doclib! = NULL) {splistitemcollection osplistcl = doclib. items; doclib. breakroleinheritance (true); foreach (splistitem item in osplistcl) {spgroup group = NULL; spuser user = NULL; try {user = web. users [@ "myname"]; // the user and group are added in this way, so the group I use here is the same as the user group = web. groups [@ "mygroup"]; //} catch (exception) {Throw new exception ("no? Yes? D.? Group ??? ");} If (group = NULL) {console. writeline (" Use ?? User ?? Is it null? "); Return;} // return; // Delete this group // item. roleassignments. remove (Group); roleassignment = new sproleassignment (Group); // tell the program what group permissions I want to add to this item. Here the read permission sproledefinition sprolwde = web. roledefinitions. getbytype (sproletype. reader); // Add the permission to the function. Here, I do not know much about roleassignment, but I only know how to use it. I will explain it later.
Roleassignment. roledefinitionbindings. Add (sprolwde );
Item. roleassignments. Add (roleassignment); // an update in the document library, and the colleague document library is updated.
Item. Update () ;}} console. readkey (); summary

I don't have a deep understanding. I can only give a rough understanding of it. There are a lot of bad things to bear with me. I'm sorry for being a child ....

Learn to be old

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.