SharePoint發行版本有SharePoint2003、SharePoint2007、Sharepoint 2010、SharePoint2013和SharePoint2016。SharePoint提供了功能強大的團隊協作環境,使得組織能夠在整個組織內部實現整合、組織、查找和提供 SharePoint站點。 上傳文檔到文檔庫,并對項目級授權,查看項目級權限方法 //在列表根目錄下創建文件夾 public static string CreatFolderToSPDocLib(string strFolderName, string strDocLibName) { string FolderPath = string.Empty; ? try { using (SPSite site = new SPSite(SiteUrl)) { using (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; } } } catch { } return FolderPath; } ? //上傳文件到文件夾,并授權給相關用戶 public static bool UpLoadFileToFolder(byte[] FileStream, string FileName, string 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; ? //斷開原來列表項所繼承的權限,使其可以設置獨立權限 listItem.BreakRoleInheritance(true); //將原來所繼承的權限通通移除 foreach (SPRoleAssignment roleAssignment in listItem.RoleAssignments) { roleAssignment.RoleDefinitionBindings.RemoveAll(); roleAssignment.Update(); listItem.Update(); } //獲取將要設置權限的用戶 SPUser myUser = web.EnsureUser(allLoginName); //定義權限分配 SPRoleAssignment myRoleAssignment = new SPRoleAssignment(myUser.LoginName, myUser.Email, myUser.Name, myUser.Notes); //綁定設置的權限 myRoleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Reader)); //把這個權限加到我們的列表中 listItem.RoleAssignments.Add(myRoleAssignment); listItem.Update(); ? web.AllowUnsafeUpdates = false; return true; } } } catch { return false; } } ? //通過ID獲取列表項 public static string GetRoleAssignmentsOfSPListItem(string ListName, int ItemID) { string reValue = string.Empty; try { using (SPSite site = new SPSite(SiteUrl)) { using (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;=""> { reValue += (role.Member.LoginName + ":" + role.RoleDefinitionBindings[i].Name + ":" + role.RoleDefinitionBindings[i].BasePermissions.ToString()); } } ? web.AllowUnsafeUpdates = false; } } } catch { } return reValue; } ? 后記:幾個簡單的方法,測試通過,可能不太完善,需要的話可以繼續完善。 Sharepoint 可以幫助企業用戶輕松完成日常工作。 |
溫馨提示:喜歡本站的話,請收藏一下本站!