コード例 #1
0
        private void SetRootSitePermissions(SPWeb web)
        {
            try
            {
                string groupOwners = web.Title.Trim() + " Owners";
                web.CreateNewGroup(groupOwners, "Use this group to grant people full control permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Administrator);

                string groupMembers = web.Title.Trim() + " Members";
                web.CreateNewGroup(groupMembers, "Use this group to grant people contribute permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Contributor);

                string groupVisitors = web.Title.Trim() + " Visitors";
                web.CreateNewGroup(groupVisitors, "Use this group to grant people read permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Reader);

                web.Update();

                Utility.ChangeSPGroupOwnerBySPGroup(web, groupOwners, groupOwners);
                Utility.ChangeSPGroupOwnerBySPGroup(web, groupMembers, groupOwners);
                Utility.ChangeSPGroupOwnerBySPGroup(web, groupVisitors, groupOwners);

                SPUser authenUsers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                if (authenUsers != null)
                {
                    SPGroup spGrp = web.Groups[groupVisitors];
                    if (spGrp != null)
                    {
                        spGrp.AddUser(authenUsers);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, AIAPortalFeatures.Infrastructure);
            }
        }
        private void SetRootSitePermissions(SPWeb web)
        {
            try
            {
                string groupOwners = web.Title.Trim() + " Owners";
                web.CreateNewGroup(groupOwners, "Use this group to grant people full control permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Administrator);

                string groupMembers = web.Title.Trim() + " Members";
                web.CreateNewGroup(groupMembers, "Use this group to grant people contribute permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Contributor);

                string groupVisitors = web.Title.Trim() + " Visitors";
                web.CreateNewGroup(groupVisitors, "Use this group to grant people read permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Reader);

                web.Update();

                Utility.ChangeSPGroupOwnerBySPGroup(web, groupOwners, groupOwners);
                Utility.ChangeSPGroupOwnerBySPGroup(web, groupMembers, groupOwners);
                Utility.ChangeSPGroupOwnerBySPGroup(web, groupVisitors, groupOwners);

                SPUser authenUsers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                if (authenUsers != null)
                {
                    SPGroup spGrp = web.Groups[groupVisitors];
                    if (spGrp != null)
                    {
                        spGrp.AddUser(authenUsers);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, AIAPortalFeatures.Infrastructure);
            }
        }