使用对象模型我正在更新组。使用PowerShell命令时,我在“RequestToJoinLeaveEmailSetting”字段中设置的值未显示。但是,当我通过对象模型获取它时,它显示设置为“RequestToJoinLeaveEmailSetting”字段的新值。
使用PowerShell命令我可以更新此字段。但是,从对象模型中我得到了自己设置的值,而不是由PowerShell设置的。
怎么样,可以同步吗?任何帮助/想法?
先谢谢了。 Mohak
这是我的代码:
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()");
}
}
答案 0 :(得分:0)
似乎您忘记在更新组属性时使用SPGroup.Update method应用更改
PS示例:
$web = Get-SPWeb $webUrl
$membersGroup = $web.AssociatedMemberGroup
$membersGroup.RequestToJoinLeaveEmailSetting = "admin@intranet.contoso.com"
$membersGroup.Update() #save group changes