简体   繁体   English

在SharePoint 2010中未正确设置RequestToJoinLeaveEmailSetting

[英]RequestToJoinLeaveEmailSetting is not being set properly in sharepoint 2010

Using object model I am updating group. 使用对象模型我正在更新组。 The value I am setting in 'RequestToJoinLeaveEmailSetting' field is not showing when using PowerShell command. 使用PowerShell命令时,未显示在“ RequestToJoinLeaveEmailSetting”字段中设置的值。 However, when I am fetching it by the object model, it is showing the new value set to 'RequestToJoinLeaveEmailSetting' field. 但是,当我通过对象模型来获取它时,它将显示设置为“ RequestToJoinLeaveEmailSetting”字段的新值。

Using the PowerShell commands I am able to update this field. 使用PowerShell命令,我可以更新此字段。 However, from the object model I am getting the value set from itself, not that is set by PowerShell. 但是,从对象模型中,我是从自身获取值集,而不是从PowerShell设置值。

How, can it be in sync? 如何同步? Any help/idea? 任何帮助/想法吗?

Thanks in advanced. 提前致谢。 Mohak 莫哈克

Here is my Code: 这是我的代码:

    SPSite Site = new SPSite(siteUrl);
    SPWeb spWeb = Site.OpenWeb();
    SPGroup spGroup = spWeb.SiteGroups[oldname];
    SPRoleCollection roles = spGroup.Roles;
    if (roles != null)
    {
    oldRoles = new ArrayList();
    foreach (SPRole role in roles)
    {
    oldRoles.Add(role.Name);
    }
    }
    // here we are comparing the old and new roles to be updated and separating out
    // which roles to be deleted and which is to be updated.
    foreach (string role in oldRoles)
    {
    if (newRoles.Contains(role))
    {
    updatedRoles.Add(role);
    }
    else
    {
    removeRoles.Add(role);
    }
    }
    foreach (string rolenames in newRoles)
    {
    if (!oldRoles.Contains(rolenames))
    {
    updatedRoles.Add(rolenames);
   }
   }
   if (removeRoles != null && removeRoles.Count > 0)
   {
   SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
   foreach (string str in removeRoles)
   {
   SPRoleDefinition role = spWeb.RoleDefinitions[str];
   //SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
   roleAssignment.RoleDefinitionBindings.Remove(role);
   spWeb.RoleAssignments.Remove(roleAssignment.Member);
   spWeb.Update();
   }
   spWeb.Update();
   }
   if (spGroup != null)
   {
   spGroup.Description = description;
   spGroup.Name = name;
   spGroup.OnlyAllowMembersViewMembership = viewprmsn;
   spGroup.AllowMembersEditMembership = edprmsn;
   spGroup.AllowRequestToJoinLeave = mbrrqst;
   spGroup.AutoAcceptRequestToJoinLeave = acptrqst;
   spGroup.RequestToJoinLeaveEmailSetting = emailid;               

   if (updatedRoles != null && updatedRoles.Count > 0)
   SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup);
   // SPRoleDefinition roleDefinition = spWeb.RoleDefinitions["Contribute"];
   foreach (string str in updatedRoles)
   {
   SPRoleDefinition roleDefinition = spWeb.RoleDefinitions[str];
   roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
   }
   spWeb.RoleAssignments.Add(roleAssignment);
   }
   //spGroup.RequestToJoinLeaveEmailSetting = emailid;
   spGroup.Update();
   }
   spWeb.Update();
   }
   catch (Exception ex)
   {
   SPTlogger.Error("-------------------------ERROR-------------------------");
   SPTlogger.Error("Error in UpdateGroup():" + ex.Message);
   throw new Exception(ex.Message);
   }
   finally
   {
   SPTlogger.Debug("<-- : UpdateGroup()");
   }
   }

It seems you forgot to apply changes using SPGroup.Update method when the group properties have been updated 似乎您已忘记在更新组属性后使用SPGroup.Update方法应用更改

PS example: PS示例:

$web = Get-SPWeb $webUrl
$membersGroup = $web.AssociatedMemberGroup
$membersGroup.RequestToJoinLeaveEmailSetting = "admin@intranet.contoso.com"
$membersGroup.Update() #save group changes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM