-2

我如何从我的自定义列表中获取 peoples 并授予他们对我创建的子站点的权限。

  public override void ItemAdded(SPItemEventProperties properties)
        {

            base.ItemAdded(properties);

我知道我需要从这个属性中得到它,但我不知道如何。阅读了大约 20 篇博客,但无法从这里找到。

            string subsitefirst = properties.ListItem["firstSub"].ToString();
            string subsitesecond = properties.ListItem["secondSub"].ToString();


           //take 1st and 2nd fields name and create with them subsites.
            if (string.IsNullOrEmpty(subsitefirst) && string.IsNullOrEmpty(subsitesecond))
            {
                return;
            }
            else
            {
                using (SPSite site = new SPSite("http://sw-mss-01:23222/Worker1/"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            //SPListItem listpeople = web.GetListItem
                            web.AllowUnsafeUpdates = true;
                            SPWeb newWeb = site.AllWebs.Add("worker1/" + subsitefirst, subsitefirst, "Site description", 1033, "STS#0", false, false);
                            SPWeb newSecondWeb = site.AllWebs.Add("worker1/" + subsitefirst + "/" + subsitesecond, subsitesecond, "Site description", 1033, "STS#0", false, false);

                        }
                        catch (Exception)
                        {
                            web.AllowUnsafeUpdates = false;
                        }

                    }`
                }
            }
        }
}
4

1 回答 1

0
string domainUserName = properties.ListItem["user"].ToString();
string groupName = "site members"; // Use the group name you want to add the user to
SPUser user = newWeb.EnsureUser(domainUserName);
SPGroup group = newWeb.Groups[groupName];
group.AddUser(user);
// Rinse and repeat for the second web
于 2013-10-25T08:01:15.820 回答