成员资格请求SPGroup sharepoint的电子邮件地址

时间:2010-12-14 05:15:44

标签: sharepoint spgroup

在sharepoint中创建Group时,我们有一个选项 “将会员请求发送到以下电子邮件地址”

用于向SPGroup发送成员资格请求。

但我们如何以编程方式设置电子邮件地址

2 个答案:

答案 0 :(得分:0)

我正在尝试在功能激活事件中完成同样的事情。我已经找到了如何创建组以及如何在对象模型中访问这些设置。您可以使用下面的示例。问题是,尽管调用了SPGroup.Update(),但我对SPGroup的这些布尔属性的更改仍然没有。创建的SPGroup仍使用默认设置(会员请求已关闭)。

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {

        SPSite site = (SPSite)properties.Feature.Parent;
        {
            using (SPWeb web = site.RootWeb)
            {
                SPGroupCollection collGroups = web.SiteGroups;
                SPUser user = web.EnsureUser("DOMAIN\\username");

                collGroups.Add("MySPGroupName", user, user, "MySPGroupDescription");
                if (!web.AssociatedGroups.Contains(collGroups["MySPGroupName"]))
                {
                    web.AssociatedGroups.Add(collGroups["MySPGroupName"]);
                }
                SPRoleAssignment assignment = new SPRoleAssignment(collGroups["MySPGroupName"]);
                SPRoleDefinition def = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
                assignment.RoleDefinitionBindings.Add(def);
                web.RoleAssignments.Add(assignment);
                web.Update();
                collGroups["MySPGroupName"].AllowMembersEditMembership = true;
                collGroups["MySPGroupName"].AllowRequestToJoinLeave = true;
                collGroups["MySPGroupName"].OnlyAllowMembersViewMembership = false;
                string emailForRequests = "username@domain.com";
                if (!String.IsNullOrEmpty(user.Email))
                    emailForRequests = user.Email;
                collGroups["MySPGroupName"].RequestToJoinLeaveEmailSetting = emailForRequests;
                collGroups["MySPGroupName"].Update();
            }
        }

    }

答案 1 :(得分:0)

如果使用SP 2013,使用PowerShell,您可以使用以下代码:

$membersGroup = $siteCollection.SiteGroups["$groupName"]
$membersGroup.RequestToJoinLeaveEmailSetting = "someone@mail.com"
$membersGroup.Update()