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