Introduction: Uploading Documents to a document library, and project-level authorization, viewing project-level permissions methods
Create a folder under the list root public static string Creatfoldertospdoclib (String strfoldername, String strdoclibname) {string FolderPath = string.
Empty; try {using (SPSite site = new SPSite (SiteURL)) {Usin G (SPWeb Web = site. OpenWeb ()) {web.
Allowunsafeupdates = true; SPListCollection lists = web.
Getlistsoftype (spbasetype.documentlibrary); Lists.
Includerootfolder = true;
SPList list = Lists[strdoclibname]; List.
Enablefoldercreation = true; SPListItem item = list. Items.Add (list.
Rootfolder.serverrelativeurl, Spfilesystemobjecttype.folder, strfoldername); Item.
Update (); List.
Update (); FolderPath = item["FileRef"].
ToString (); Web.
Allowunsafeupdates = false;
The catch {} return folderpath; //Upload files to folder and authorize to relevant users public static bool Uploadfiletofolder (byte[] FileStream, string FileName, str ing FolderPath, string allloginname) {try {using (SPSite site = new SPSite (SiteURL)) {using (SPWeb Web = site. OpenWeb ()) {web.
Allowunsafeupdates = true; SPFolder folder = web.
GetFolder (FolderPath); SPListItem ListItem = folder. Files.add (FileName, FileStream).
Item;
Disconnect the permissions inherited from the original list item so that it can set independent permissions listitem.breakroleinheritance (TRUE); Remove all previously inherited permissions from foreach (SPRoleAssignment roleassignment inlistitem.roleassignments) {RoleAssignment.RoleDefinitionBindings.Re
Moveall ();
Roleassignment.update ();
Listitem.update (); //Get the user SPUser MyUser = web that will set permissions.
Ensureuser (Allloginname); Define permission Assignment SPRoleAssignment myroleassignment = new SPRoleAssignment (Myuser.loginname, Myuser.email,
Myuser.name, myuser.notes); The permissions set by the binding are MYROLEASSIGNMENT.ROLEDEFINITIONBINDINGS.ADD (web.
Roledefinitions.getbytype (Sproletype.reader));
Add this permission to our list of LISTITEM.ROLEASSIGNMENTS.ADD (myroleassignment);
Listitem.update (); Web.
Allowunsafeupdates = false;
return true;
} catch {return false; Get list item public static string Getroleassignmentsofsplistitem by ID (string listname, int ItemID) {String revalue = string.
Empty; try {using (SPSite site = new SPSite (SiteURL)) {Usin G (SPWeb Web = site. OpenWeb ()) {web.
Allowunsafeupdates = true; SPList list = web.
Lists[listname]; SPListItem item = list.
Items.getitembyid (ItemID); Sproleassignmentcollection Rolecoll = Item.
roleassignments; foreach (SPRoleAssignment role in Rolecoll) {for (int i = 0; i < Role. Roledefinitionbindings.count; i++) {REvalue = = (role. Member.loginname + ":" + role. Roledefinitionbindings[i]. Name + ":" + role. Roledefinitionbindings[i].
Basepermissions.tostring ()); }} web.
Allowunsafeupdates = false;
The catch {} return revalue; }
PostScript: A few simple methods, test pass, may not be perfect, need words can continue to improve.
Author: cnblogs Lin Yu
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/