本文整理汇总了C#中SPList.BreakRoleInheritance方法的典型用法代码示例。如果您正苦于以下问题:C# SPList.BreakRoleInheritance方法的具体用法?C# SPList.BreakRoleInheritance怎么用?C# SPList.BreakRoleInheritance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPList
的用法示例。
在下文中一共展示了SPList.BreakRoleInheritance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BreakRoleInheritance
/// <summary>
/// Breaks the role assignment inheritance for the list and gives the current list its own copy of the role assignments.
/// </summary>
/// <param name = "list"></param>
/// <param name = "copyRoleAssigements"></param>
public static void BreakRoleInheritance(SPList list, bool copyRoleAssigements)
{
if (!list.HasUniqueRoleAssignments)
{
list.BreakRoleInheritance(copyRoleAssigements);
list.Update();
}
}
示例2: ModifyListPermissions
private void ModifyListPermissions(SPList list)
{
// Modifying the permissions for the list to restrict the students for direct list items operations
try
{
if (!list.HasUniqueRoleAssignments)
{
var web = list.ParentWeb;
list.BreakRoleInheritance(false, false);
var group = web.SiteGroups[Utilities.StudentsGroupName];
var roleAssignment = new SPRoleAssignment(group);
SPRoleDefinition spRole = web.RoleDefinitions["Read"];
roleAssignment.RoleDefinitionBindings.Add(spRole);
list.RoleAssignments.Add(roleAssignment);
group = web.SiteGroups[Utilities.FacultyGroupName];
roleAssignment = new SPRoleAssignment(group);
spRole = web.RoleDefinitions["Full Control"];
roleAssignment.RoleDefinitionBindings.Add(spRole);
list.RoleAssignments.Add(roleAssignment);
list.Update();
}
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, ex.Message, new object[] { ex.StackTrace });
}
}
示例3: CopyListRoleAssignments
public static void CopyListRoleAssignments(SPList sourceList, SPList destinationList)
{
//First check if the Source List has Unique permissions
if (sourceList.HasUniqueRoleAssignments) {
//Break List permission inheritance first
destinationList.BreakRoleInheritance(true);
//Remove current role assignemnts
while (destinationList.RoleAssignments.Count > 0) {
destinationList.RoleAssignments.Remove(0);
}
//Copy Role Assignments from source to destination list.
foreach (SPRoleAssignment sourceRoleAsg in sourceList.RoleAssignments) {
SPRoleAssignment destinationRoleAsg = null;
//Get the source member object
SPPrincipal member = sourceRoleAsg.Member;
//Check if the member is a user
try {
SPUser sourceUser = (SPUser)member;
SPUser destinationUser = destinationList.ParentWeb.Users.GetByEmail(sourceUser.Email);
destinationRoleAsg = new SPRoleAssignment(destinationUser);
}
catch { }
if (destinationRoleAsg == null) {
//Check if the member is a group
try {
SPGroup sourceGroup = (SPGroup)member;
SPGroup destinationGroup = destinationList.ParentWeb.SiteGroups[sourceGroup.Name];
destinationRoleAsg = new SPRoleAssignment(destinationGroup);
}
catch { }
}
//At this state we should have the role assignment established either by user or group
if (destinationRoleAsg != null) {
foreach (SPRoleDefinition sourceRoleDefinition in sourceRoleAsg.RoleDefinitionBindings) {
try { destinationRoleAsg.RoleDefinitionBindings.Add(destinationList.ParentWeb.RoleDefinitions[sourceRoleDefinition.Name]); }
catch { }
}
if (destinationRoleAsg.RoleDefinitionBindings.Count > 0) {
//handle additon of an existing permission assignment error
try { destinationList.RoleAssignments.Add(destinationRoleAsg); }
catch (ArgumentException) { }
}
}
}
//Does not require list update
//destinationList.Update();
}
else
//No need to assign permissions
return;
}
示例4: SetListAsCatalog
/// <summary>
/// Set a SharePoint as a product catalog without navigation term associated
/// Note: For more information, see PublishingCatalogUtility in Microsoft.SharePoint.Publishing
/// </summary>
/// <param name="list">The SharePoint list.</param>
/// <param name="availableFields">List of internal field names that are available through the catalog.</param>
/// <param name="activateAnonymousAccess">if set to <c>true</c> [activate anonymous access].</param>
/// <returns>
/// The SharePoint list configured as a catalog.
/// </returns>
private SPList SetListAsCatalog(SPList list, IEnumerable<string> availableFields, bool activateAnonymousAccess)
{
// TODO: Validate "availableFields" param name. Should it be availableManagedProperties? The comment says internal name. What does FurlFields really expect as format?
this.logger.Info("Start method 'SetListAsCatalog' for list: '{0}'", list.RootFolder.Url);
// Add properties for catalog publishing on the root folder
list.IndexedRootFolderPropertyKeys.Add("PublishingCatalogSettings");
list.IndexedRootFolderPropertyKeys.Add("IsPublishingCatalog");
if (activateAnonymousAccess)
{
// Allow anonymous access on the parentWeb
list.ParentWeb.FirstUniqueAncestorWeb.AnonymousPermMask64 |= SPBasePermissions.AnonymousSearchAccessWebLists;
// Break list inheritance for anonymous access
list.BreakRoleInheritance(true, false);
// Allow anonymous access on the list
list.AnonymousPermMask64 |= SPBasePermissions.AnonymousSearchAccessList;
}
var fieldList = new Collection<string>();
// For fields name, you need to pass the internal name of the column directly followed by "OWSTEXT"
foreach (var availableField in availableFields)
{
fieldList.Add("\"" + availableField + "\"");
}
var friendlyUrlFieldsProperty = string.Join(",", fieldList.ToArray());
var rootFolder = list.RootFolder;
rootFolder.Properties["IsPublishingCatalog"] = "True";
rootFolder.Properties["PublishingCatalogSettings"] = "{\"FurlFields\":[" + friendlyUrlFieldsProperty + "],\"TaxonomyFieldMap\":[]}";
rootFolder.Properties["vti_indexedpropertykeys"] = "UAB1AGIAbABpAHMAaABpAG4AZwBDAGEAdABhAGwAbwBnAFMAZQB0AHQAaQBuAGcAcwA=|SQBzAFAAdQBiAGwAaQBzAGgAaQBuAGcAQwBhAHQAYQBsAG8AZwA=|";
rootFolder.Update();
list.Update();
return list;
}
示例5: GrantGroupListLevelPermisisons
/// <summary>
/// Grants list level permissions to a target sharepoint on the HTS site.
/// </summary>
/// <param name="spTargetGroup">Represents an instance of a HTS security group.</param>
/// <param name="spAssignRoleType">Represents an instance of a target HTS role type.</param>
/// <param name="spTargetList">Represents an instance of the target list where we grant the security group permission to.</param>
private static void GrantGroupListLevelPermisisons(SPGroup spTargetGroup, SPRoleType spAssignRoleType, SPList spTargetList)
{
if (spTargetList.HasUniqueRoleAssignments == false)
{
spTargetList.BreakRoleInheritance(true);
}
/* Remove the user from the role assignment. */
spTargetList.RoleAssignments.Remove(spTargetGroup);
SPRoleAssignment roleAssign = new SPRoleAssignment(spTargetGroup);
SPRoleDefinition roleDef = spTargetList.ParentWeb.RoleDefinitions.GetByType(spAssignRoleType);
roleAssign.RoleDefinitionBindings.Add(roleDef);
spTargetList.RoleAssignments.Add(roleAssign);
}