コード例 #1
0
        /// <summary>
        /// Will scan the web site groups for groups to provision and retrieve
        /// </summary>
        /// <param name="hostWeb">The host web to which the groups will be created</param>
        /// <param name="groupDef">The collection of groups to retrieve and/or provision</param>
        /// <returns></returns>
        public static Microsoft.SharePoint.Client.Group GetOrCreateSiteGroups(this Web hostWeb, SPGroupDefinitionModel groupDef)
        {
            hostWeb.EnsureProperties(hw => hw.CurrentUser);
            var context = hostWeb.Context;

            // Create Group
            var groupCreationInfo = new GroupCreationInformation
            {
                Title       = groupDef.Title,
                Description = groupDef.Description
            };

            var oGroup = hostWeb.SiteGroups.Add(groupCreationInfo);

            context.Load(oGroup);

            oGroup.Owner = hostWeb.CurrentUser;
            oGroup.OnlyAllowMembersViewMembership = groupDef.OnlyAllowMembersViewMembership;
            oGroup.AllowMembersEditMembership     = groupDef.AllowMembersEditMembership;
            oGroup.AllowRequestToJoinLeave        = groupDef.AllowRequestToJoinLeave;
            oGroup.AutoAcceptRequestToJoinLeave   = groupDef.AutoAcceptRequestToJoinLeave;
            oGroup.Update();

            context.Load(oGroup, g => g.Id, g => g.Title);
            context.ExecuteQueryRetry();


            return(oGroup);
        }
コード例 #2
0
ファイル: NewGroup.cs プロジェクト: ADefWebserver/PnP
        protected override void ExecuteCmdlet()
        {
            User groupOwner = null;
            if (!string.IsNullOrEmpty(Owner))
            {
                groupOwner = this.SelectedWeb.EnsureUser(Owner);
            }
            GroupCreationInformation groupCI = new GroupCreationInformation();
            groupCI.Title = Title;
            groupCI.Description = Description;

            var group = this.SelectedWeb.SiteGroups.Add(groupCI);

            ClientContext.Load(group);
            ClientContext.Load(group.Users);
            ClientContext.ExecuteQuery();

            if (AllowRequestToJoinLeave)
                group.AllowRequestToJoinLeave = true;

            if (AutoAcceptRequestToJoinLeave)
                group.AutoAcceptRequestToJoinLeave = true;

            if (!string.IsNullOrEmpty(Owner))
                group.Owner = groupOwner;

            group.Update();
            ClientContext.ExecuteQuery();
            WriteObject(group);

            
        }
コード例 #3
0
ファイル: SecurityExtensions.cs プロジェクト: Xylon5/API
        /// <summary>
        /// Adds a group
        /// </summary>
        /// <param name="web">Site to add the group to</param>
        /// <param name="groupName">Name of the group</param>
        /// <param name="groupDescription">Description of the group</param>
        /// <param name="groupIsOwner">Sets the created group as group owner if true</param>
        /// <param name="updateAndExecuteQuery">Set to false to postpone the executequery call</param>
        /// <returns>The created group</returns>
        public static Group AddGroup(this Web web, string groupName, string groupDescription, bool groupIsOwner, bool updateAndExecuteQuery = true)
        {
            if (string.IsNullOrEmpty(groupName))
            {
                throw new ArgumentNullException("groupName");
            }

            GroupCreationInformation groupCreationInformation = new GroupCreationInformation();

            groupCreationInformation.Title       = groupName;
            groupCreationInformation.Description = groupDescription;
            Group group = web.SiteGroups.Add(groupCreationInformation);

            if (groupIsOwner)
            {
                group.Owner = group;
            }

            group.OnlyAllowMembersViewMembership = false;
            group.Update();

            if (updateAndExecuteQuery)
            {
                web.Context.ExecuteQueryRetry();
            }

            return(group);
        }
コード例 #4
0
        public static void CreateSecurityGroups(IList <string> groupNames)
        {
            var context = SharePointOnlineHelper.GetElevatedContext();
            var results = new Dictionary <string, int>();

            try
            {
                using (context)
                {
                    foreach (var group in groupNames)
                    {
                        try
                        {
                            var groupInfo = new GroupCreationInformation();
                            groupInfo.Title = group;
                            context.Web.SiteGroups.Add(groupInfo);
                            context.ExecuteQuery();
                        }
                        catch (Exception e)
                        {
                            var c = e.Message;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var message = e.Message;
            }
        }
コード例 #5
0
        protected override void ExecuteCmdlet()
        {
            var url = PnPConnection.Current.Url;

            if (ParameterSpecified(nameof(Site)))
            {
                url = Site.Url;
            }
            var rootWeb = this.Tenant.GetSiteByUrl(url).RootWeb;

            var roleDefinitions = GetRoleDefinitions(rootWeb);

            var roleDefCollection = new RoleDefinitionBindingCollection(ClientContext);

            foreach (var permissionToAdd in PermissionLevels)
            {
                if (!roleDefinitions.Contains(permissionToAdd))
                {
                    throw new PSArgumentException($"Permission level {permissionToAdd} not defined in site");
                }
                var existingRoleDef = rootWeb.RoleDefinitions.GetByName(permissionToAdd);
                roleDefCollection.Add(existingRoleDef);
            }
            var groupCI = new GroupCreationInformation();

            groupCI.Title = Name;
            var group = rootWeb.SiteGroups.Add(groupCI);

            rootWeb.RoleAssignments.Add(group, roleDefCollection);
            ClientContext.Load(group, g => g.Title, g => g.LoginName, g => g.Users, g => g.Owner.LoginName, g => g.OwnerTitle);
            ClientContext.ExecuteQueryRetry();
            var siteGroup = new SiteGroup(ClientContext, Tenant, group, rootWeb);

            WriteObject(siteGroup);
        }
コード例 #6
0
        public static Group CreateSiteGroup(this Web site, GroupCreationInformation groupCreateInfo)
        {
            Group group = site.SiteGroups.Add(groupCreateInfo);

            site.Context.Load(group);
            site.Context.ExecuteQuery();

            return(group);
        }
コード例 #7
0
        // This function will get triggered/executed when a new message is written
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage(
            [QueueTrigger(O365ProjectsAppConstants.Blob_Storage_Queue_Name)] GroupCreationInformation groupCreation,
            TextWriter log)
        {
            log.WriteLine(String.Format("Starting Job: {0} - Creating Group: {1}",
                                        groupCreation.JobId, groupCreation.Name));

            // Convert photo into a MemoryStream
            MemoryStream photoStream = new MemoryStream();

            photoStream.Write(groupCreation.Photo, 0, groupCreation.Photo.Length);
            photoStream.Position = 0;

            // Create the Office 365 Group
            var group = GraphRemoteActions.CreateOffice365Group(
                new Group
            {
                DisplayName     = groupCreation.Name,
                MailEnabled     = true,
                SecurityEnabled = true,
                GroupTypes      = new List <String>(new String[] { "Unified" }),
                MailNickname    = groupCreation.Name,
            },
                groupCreation.Members,
                photoStream,
                groupCreation.AccessToken);

            // Send the welcome message into the group's conversation
            GraphRemoteActions.SendMessageToGroupConversation(group.Id,
                                                              new Conversation
            {
                Topic   = $"Let's manage the Project {groupCreation.Name}!",
                Threads = new List <ConversationThread>(
                    new ConversationThread[] {
                    new ConversationThread
                    {
                        Topic = "We've just created this Business Project",
                        Posts = new List <ConversationThreadPost>(
                            new ConversationThreadPost[]
                        {
                            new ConversationThreadPost
                            {
                                Body = new ItemBody
                                {
                                    Content = "<h1>Welcome to this Business Project</h1>",
                                    Type    = BodyType.Html,
                                },
                            }
                        })
                    }
                })
            },
                                                              groupCreation.AccessToken);

            log.WriteLine("Completed Job execution");
        }
コード例 #8
0
        public static Group CreateSiteGroup(this Web site, string groupName, string groupDesc)
        {
            GroupCreationInformation groupCreateInfo = new GroupCreationInformation
            {
                Title       = groupName,
                Description = groupDesc
            };

            return(CreateSiteGroup(site, groupCreateInfo));
        }
コード例 #9
0
        /// <summary>
        /// グループ名と説明を指定して、
        /// グループを追加します。
        /// </summary>
        /// <param name="this">GroupCollection</param>
        /// <param name="name">グループ名</param>
        /// <param name="description">説明</param>
        /// <returns>追加したグループを返します。</returns>
        public static Group Add(this GroupCollection @this, string name, string description)
        {
            var g = new GroupCreationInformation()
            {
                Title       = name,
                Description = description,
            };

            return(@this.Add(g));
        }
コード例 #10
0
        /// <summary>
        /// Creates group with restricted access permissions on client site collection to allow functionality in matter landing page
        /// </summary>
        /// <param name="siteUrl">URL of the client site collection to create group at</param>
        /// <param name="onlineCredentials">credentials to access site</param>
        internal static void CreateRestrictedGroup(string siteUrl, SharePointOnlineCredentials onlineCredentials)
        {
            try
            {
                Console.WriteLine("Creating " + ConfigurationManager.AppSettings["restrictedAccessGroupName"] + " group.");

                using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    clientContext.Credentials = onlineCredentials;
                    Site collSite = clientContext.Site;
                    Web  site     = clientContext.Web;

                    //Create group
                    GroupCollection collGroup = site.SiteGroups;
                    clientContext.Load(collGroup, group => group.Include(properties => properties.Title));
                    clientContext.Load(site.RoleDefinitions);
                    clientContext.ExecuteQuery();

                    Group currentGrp = (from grp in collGroup where grp.Title == ConfigurationManager.AppSettings["restrictedAccessGroupName"] select grp).FirstOrDefault();
                    if (currentGrp != null)
                    {
                        collGroup.Remove(currentGrp);
                    }

                    GroupCreationInformation grpInfo = new GroupCreationInformation();
                    grpInfo.Title       = ConfigurationManager.AppSettings["restrictedAccessGroupName"];
                    grpInfo.Description = ConfigurationManager.AppSettings["restrictedAccessGroupDescription"];
                    collGroup.Add(grpInfo);
                    site.Update();
                    clientContext.Load(collGroup);
                    clientContext.ExecuteQuery();

                    currentGrp = (from grp in collGroup where grp.Title == ConfigurationManager.AppSettings["restrictedAccessGroupName"] select grp).FirstOrDefault();

                    AssignPermissionToGroup(clientContext, collSite, site, currentGrp);

                    //Add everyone to group
                    User allUsers = clientContext.Web.EnsureUser(ConfigurationManager.AppSettings["allUsers"]);
                    clientContext.Load(allUsers);
                    clientContext.ExecuteQuery();

                    currentGrp.Users.AddUser(allUsers);
                    site.Update();
                    clientContext.Load(currentGrp);
                    clientContext.ExecuteQuery();

                    Console.WriteLine("Created " + ConfigurationManager.AppSettings["restrictedAccessGroupName"] + " group successfully");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred while creating group: " + exception.Message);
            }
        }
コード例 #11
0
        public void Create(string title, string description, string strOwner, string[] permissions = null, IList <string> users = null)
        {
            try
            {
                if (string.IsNullOrEmpty(title))
                {
                    throw new ArgumentException("O title precisa ser informado");
                }
                if (string.IsNullOrEmpty(strOwner))
                {
                    throw new ArgumentException("O Owner precisa ser informado");
                }
                if (permissions == null || permissions.Length == 0)
                {
                    throw new ArgumentException("É necessário informar ao menos uma permissão para o grupo");
                }

                GroupCreationInformation groupCreationInfo = new GroupCreationInformation
                {
                    Title       = title,
                    Description = description
                };

                User  owner = _ctx.Web.EnsureUser(strOwner);
                Group group = _ctx.Web.SiteGroups.Add(groupCreationInfo);
                RoleDefinitionBindingCollection objBindingColl = new RoleDefinitionBindingCollection(_ctx);
                if (permissions != null && permissions.Length > 0)
                {
                    foreach (var permission in permissions)
                    {
                        RoleDefinition customPermissionRole = _ctx.Web.RoleDefinitions.GetByName(permission);
                        objBindingColl.Add(customPermissionRole);
                    }
                }
                _ctx.Web.RoleAssignments.Add(group, objBindingColl);
                if (users != null)
                {
                    foreach (var user in users)
                    {
                        User member = _ctx.Web.EnsureUser(user);
                        group.Users.AddUser(member);
                    }
                }

                group.Update();
                _ctx.ExecuteQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #12
0
        public static async Task CreateGroup(this ClientContext clientContext, string name)
        {
            if (await clientContext.GroupExists(name))
            {
                throw new Exception($@"""{name}"" group already exists!");
            }

            var groupCreationInformation = new GroupCreationInformation {
                Title = name
            };

            clientContext.Web.SiteGroups.Add(groupCreationInformation);
            await clientContext.ExecuteQueryAsync();
        }
コード例 #13
0
        public void CreateGroup(string password, string title)
        {
            var clientContext = authentication.Credentials(password);
            GroupCreationInformation groupCreationInfo = new GroupCreationInformation();

            groupCreationInfo.Title = "grourep";
            //groupCreationInfo.Description = ConfigurationManager.AppSettings["GroupDesc"];
            Group oGroup = clientContext.Web.SiteGroups.Add(groupCreationInfo);

            clientContext.Load(oGroup,
                               group => group.Title);
            clientContext.ExecuteQuery();
            AssignGroupRole(password, groupCreationInfo.Title, title);
        }
コード例 #14
0
        public ActionResult StartNewProject()
        {
            Guid groupId     = Guid.NewGuid();
            var  groupNameId = groupId.ToString().Replace("-", "");

            MemoryStream memPhoto = new MemoryStream();

            using (FileStream fs = new FileStream(Server.MapPath("~/AppIcon.png"),
                                                  FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                Byte[] newPhoto = new Byte[fs.Length];
                fs.Read(newPhoto, 0, (Int32)(fs.Length - 1));
                memPhoto.Write(newPhoto, 0, newPhoto.Length);
                memPhoto.Position = 0;
            }

            GroupCreationInformation job = new GroupCreationInformation {
                AccessToken = MicrosoftGraphHelper.GetAccessTokenForCurrentUser(
                    O365ProjectsAppSettings.MicrosoftGraphResourceId),
                JobId   = groupId,
                Name    = groupNameId,
                Members = new String[] {
                    "*****@*****.**",
                    "*****@*****.**"
                },
                Photo = memPhoto.ToArray(),
            };

            try
            {
                // Get the storage account for Azure Storage Queue
                CloudStorageAccount storageAccount =
                    CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);

                // Get queue ... and create if it does not exist
                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                CloudQueue       queue       = queueClient.GetQueueReference(O365ProjectsAppConstants.Blob_Storage_Queue_Name);
                queue.CreateIfNotExists();

                // Add entry to queue
                queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(job)));
            }
            catch (Exception)
            {
                // TODO: Handle any exception thrown by the object of type CloudQueue
            }

            return(View());
        }
コード例 #15
0
        public static void AddRoleWithPermissions(this Web value, ClientRuntimeContext context, string title, RoleType roleType)
        {
            var groupCreationInfo = new GroupCreationInformation
            {
                Title = title
            };
            var ownersGroup                     = value.SiteGroups.Add(groupCreationInfo);
            var ownersRoleDefinition            = value.RoleDefinitions.GetByType(roleType);
            var ownersRoleDefinitionBindingColl = new RoleDefinitionBindingCollection(context)
            {
                ownersRoleDefinition
            };

            value.RoleAssignments.Add(ownersGroup, ownersRoleDefinitionBindingColl);
        }
コード例 #16
0
        /// <summary>
        /// Will scan the web site groups for groups to provision and retrieve
        /// </summary>
        /// <param name="hostWeb">The host web to which the groups will be created</param>
        /// <param name="groupsToProvision">The collection of groups to retrieve and/or provision</param>
        /// <returns></returns>
        public static IList <SPGroupDefinitionModel> GetOrCreateSiteGroups(this Web hostWeb, List <SPGroupDefinitionModel> groupsToProvision)
        {
            var siteGroups = new List <SPGroupDefinitionModel>();
            var context    = hostWeb.Context;

            var groups = hostWeb.SiteGroups;

            context.Load(groups, g => g.Include(inc => inc.Id, inc => inc.Title));
            context.ExecuteQuery();

            foreach (var groupDef in groupsToProvision)
            {
                if (groups.Any(g => g.Title.Equals(groupDef.Title, StringComparison.CurrentCultureIgnoreCase)))
                {
                    var group = groups.FirstOrDefault(g => g.Title.Equals(groupDef.Title, StringComparison.CurrentCultureIgnoreCase));
                    siteGroups.Add(new SPGroupDefinitionModel()
                    {
                        Id = group.Id, Title = group.Title
                    });
                    continue;
                }

                // Create Group
                var groupCreationInfo = new GroupCreationInformation();
                groupCreationInfo.Title       = groupDef.Title;
                groupCreationInfo.Description = groupDef.Description;

                var oGroup = hostWeb.SiteGroups.Add(groupCreationInfo);
                context.Load(oGroup);
                oGroup.Owner = hostWeb.CurrentUser;
                oGroup.OnlyAllowMembersViewMembership = groupDef.OnlyAllowMembersViewMembership;
                oGroup.AllowMembersEditMembership     = groupDef.AllowMembersEditMembership;
                oGroup.AllowRequestToJoinLeave        = groupDef.AllowRequestToJoinLeave;
                oGroup.AutoAcceptRequestToJoinLeave   = groupDef.AutoAcceptRequestToJoinLeave;
                oGroup.Update();
                context.Load(oGroup, g => g.Id, g => g.Title);
                context.ExecuteQuery();
                siteGroups.Add(new SPGroupDefinitionModel()
                {
                    Id = oGroup.Id, Title = oGroup.Title
                });
            }

            return(siteGroups);
        }
コード例 #17
0
        public override void AddSiteGroup(string name, SPDGUser owner, SPDGUser defaultUser, string description)
        {
            if (_site.RootWeb.ID != this.ID)
            {
                _site.RootWeb.AddSiteGroup(name, owner, defaultUser, description);
            }
            invalidateSiteGroups();
            GroupCreationInformation groupCreateInformation = new GroupCreationInformation();

            groupCreateInformation.Title       = name;
            groupCreateInformation.Description = description;

            var group = _web.SiteGroups.Add(groupCreateInformation);

            group.Owner = ((SPDGClientUser)owner).User;
            group.Update();
            _context.ExecuteQuery();
        }
コード例 #18
0
        private static void CreateApproversGroups()
        {
            GroupCreationInformation clientsApproversGroupInfo = new GroupCreationInformation()
            {
                Description = "Clients Credits Approvers group",
                Title       = "Clients Credits Approvers"
            };

            GroupCreationInformation companiesApproversGroupInfo = new GroupCreationInformation()
            {
                Description = "Companies Credits Approvers group",
                Title       = "Companies Credits Approvers"
            };

            web.SiteGroups.Add(clientsApproversGroupInfo);
            web.SiteGroups.Add(companiesApproversGroupInfo);
            context.ExecuteQuery();
        }
コード例 #19
0
        private static Group EnsureGroup(Web web, string groupName)
        {
            ExceptionHandlingScope ensureGroupScope = new ExceptionHandlingScope(web.Context);

            using (ensureGroupScope.StartScope())
            {
                using (ensureGroupScope.StartTry())
                {
                    web.SiteGroups.GetByName(groupName);
                }

                using (ensureGroupScope.StartCatch())
                {
                    GroupCreationInformation groupCreationInfo = new GroupCreationInformation();
                    groupCreationInfo.Title = groupName;
                    web.SiteGroups.Add(groupCreationInfo);
                }
            }

            return(web.SiteGroups.GetByName(groupName));
        }
コード例 #20
0
ファイル: NewGroup.cs プロジェクト: vcx/PnP
        protected override void ExecuteCmdlet()
        {
            User groupOwner = null;

            if (!string.IsNullOrEmpty(Owner))
            {
                groupOwner = this.SelectedWeb.EnsureUser(Owner);
            }
            GroupCreationInformation groupCI = new GroupCreationInformation();

            groupCI.Title       = Title;
            groupCI.Description = Description;

            var group = this.SelectedWeb.SiteGroups.Add(groupCI);

            ClientContext.Load(group);
            ClientContext.Load(group.Users);
            ClientContext.ExecuteQuery();

            if (AllowRequestToJoinLeave)
            {
                group.AllowRequestToJoinLeave = true;
            }

            if (AutoAcceptRequestToJoinLeave)
            {
                group.AutoAcceptRequestToJoinLeave = true;
            }

            if (!string.IsNullOrEmpty(Owner))
            {
                group.Owner = groupOwner;
            }

            group.Update();
            ClientContext.ExecuteQuery();
            WriteObject(group);
        }
コード例 #21
0
        public void CreateCustomGroup(string groupName)
        {
            context = AuthenticationManager.CreateClientContext(rootUrl, user, password);
            var web = context.Web;

            context.Load(web.RoleDefinitions);
            context.Load(web, w => w.Title, w => w.Description);

            GroupCreationInformation groupCreationInfo = new GroupCreationInformation();

            groupCreationInfo.Title       = groupName;
            groupCreationInfo.Description = "Custom Group Created...";
            User  owner  = web.EnsureUser(user);
            User  member = web.EnsureUser(userAn);
            Group group  = web.SiteGroups.Add(groupCreationInfo);

            group.Owner = owner;
            group.Users.AddUser(member);
            group.Update();
            context.ExecuteQuery();

            var roleDefinitions = web.RoleDefinitions;

            // Get test level Role Definition
            var permissionLevel = roleDefinitions.GetByName(testlevel);

            context.Load(permissionLevel);
            context.ExecuteQuery();

            RoleDefinitionBindingCollection collRDB = new RoleDefinitionBindingCollection(context);

            collRDB.Add(permissionLevel);

            // Bind the Newly Created Permission Level to Owners Group
            web.RoleAssignments.Add(group, collRDB);

            context.ExecuteQuery();
        }
コード例 #22
0
 public void CrearGrupo()
 {
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine("    Grupo: " + Title);
     try
     {
         GroupCreationInformation Grupo = new GroupCreationInformation();
         Grupo.Title       = Title;
         Grupo.Description = Desc;
         User  EmpresaOwner  = Ctx.Web.EnsureUser(User);
         User  EmpresaMember = Ctx.Web.EnsureUser(User);
         Group Empresa       = Ctx.Web.SiteGroups.Add(Grupo);
         Empresa.Owner = EmpresaOwner;
         Empresa.Users.AddUser(EmpresaMember);
         Empresa.Update();
         Ctx.ExecuteQuery();
     }
     catch (Exception ex) {
         Console.ForegroundColor = ConsoleColor.Magenta;
         Console.WriteLine("    Grupo Existentes");
         Console.ResetColor();
     }
 }
コード例 #23
0
ファイル: Program.cs プロジェクト: yabroffs/mattercenter
        /// <summary>
        /// Method to check if a group exists and create a new one
        /// </summary>
        /// <param name="collGroup">group collection</param>
        /// <param name="item">data storage</param>
        /// <param name="site">site object</param>
        /// <param name="clientContext">client context</param>
        /// <returns>returns group object</returns>
        private static Group CheckAndCreateGroup(GroupCollection collGroup, DataStorage item, Web site, ClientContext clientContext)
        {
            Group currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();

            if (currentGrp != null)
            {
                Console.WriteLine("Deleting group " + item.GroupName + " as it is already present");
                collGroup.Remove(currentGrp);
            }

            //Creating group
            Console.WriteLine("Creating group " + item.GroupName);
            GroupCreationInformation grpInfo = new GroupCreationInformation();

            grpInfo.Title       = item.GroupName;
            grpInfo.Description = item.GroupDesc;
            collGroup.Add(grpInfo);
            site.Update();
            clientContext.Load(collGroup);
            clientContext.ExecuteQuery();
            Console.WriteLine("Successfully created group " + item.GroupName);
            currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();
            return(currentGrp);
        }
コード例 #24
0
        /// <summary>
        /// Adds a group
        /// </summary>
        /// <param name="web">Site to add the group to</param>
        /// <param name="groupName">Name of the group</param>
        /// <param name="groupDescription">Description of the group</param>
        /// <param name="groupIsOwner">Sets the created group as group owner if true</param>
        /// <param name="updateAndExecuteQuery">Set to false to postpone the executequery call</param>
        /// <returns>The created group</returns>
        public static Group AddGroup(this Web web, string groupName, string groupDescription, bool groupIsOwner, bool updateAndExecuteQuery = true)
        {
            if (string.IsNullOrEmpty(groupName))
                throw new ArgumentNullException("groupName");

            GroupCreationInformation groupCreationInformation = new GroupCreationInformation();
            groupCreationInformation.Title = groupName;
            groupCreationInformation.Description = groupDescription;
            Group group = web.SiteGroups.Add(groupCreationInformation);
            if (groupIsOwner)
            {
                group.Owner = group;
            }

            group.OnlyAllowMembersViewMembership = false;
            group.Update();

            if (updateAndExecuteQuery)
            {
                web.Context.ExecuteQueryRetry();
            }

            return group;
        }
コード例 #25
0
        public void CreateGroup(ObservableCollection<PermissionLevel> permissionLevels, string siteUrl, bCheck.Admin.Data.Group gp, Action<bool, Exception> reply)
         {
                ClientRequestSucceededEventHandler SuccessHandler = null;
                ClientRequestFailedEventHandler FailureHandler = null;

                Principal principal = null;    
                
               ClientContext ictx = null;
                if (siteUrl == Constants.Optional)                
                       ictx = _client;                      
                else
                    ictx =  new ClientContext(siteUrl);

                GroupCreationInformation grp = new GroupCreationInformation(){
                    Title = gp.Title,
                    Description =gp.Description
                };

                if (gp.Owner.PrincipalType == PrincipalType.SharePointGroup)
                    principal = ictx.Web.SiteGroups.GetById(gp.Owner.PrincipalId);
                else if (gp.Owner.PrincipalType == PrincipalType.User)
                    principal = ictx.Web.EnsureUser(gp.Owner.LoginName);
                
                Group group = ictx.Web.SiteGroups.Add(grp);
                group.Owner = principal;
                group.AllowMembersEditMembership = gp.AllowMembersEditMembership;
                group.OnlyAllowMembersViewMembership = gp.OnlyAllowMembersViewMembership;
                group.Update();

                if (permissionLevels != null && permissionLevels.Count > 0)
                {
                    RoleDefinitionBindingCollection rbc = new RoleDefinitionBindingCollection(ictx);
                    foreach (PermissionLevel pl in permissionLevels)
                    {
                        RoleDefinition rd = ictx.Web.RoleDefinitions.GetByName(pl.LevelName);
                        rbc.Add(rd);
                    }    
                    
                    ictx.Web.RoleAssignments.Add(group, rbc);                
                }
 
                SuccessHandler = (s, e) =>
                {
                    reply(true, null);
                };                

                FailureHandler = (s, e) =>
                {
                    Logger.AddLog(_log, e.Exception);
                    reply(false, e.Exception);
                };

                ictx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
             }
コード例 #26
0
ファイル: NewGroup.cs プロジェクト: AaronSaikovski/PnP
        protected override void ExecuteCmdlet()
        {
            var web = this.SelectedWeb;

            GroupCreationInformation groupCI = new GroupCreationInformation();
            groupCI.Title = Title;
            groupCI.Description = Description;

            var group = web.SiteGroups.Add(groupCI);

            ClientContext.Load(group);
            ClientContext.Load(group.Users);
            ClientContext.ExecuteQuery();
            bool dirty = false;
            if (AllowRequestToJoinLeave)
            {
                group.AllowRequestToJoinLeave = true;
                dirty = true;
            }

            if (AutoAcceptRequestToJoinLeave)
            {
                group.AutoAcceptRequestToJoinLeave = true;
                dirty = true;
            }
            if (dirty)
            {
                group.Update();
                ClientContext.ExecuteQuery();
            }

            if (!string.IsNullOrEmpty(Owner))
            {
                Principal groupOwner = null;

                try
                {
                    groupOwner = web.EnsureUser(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQuery();
                }
                catch
                {
                    groupOwner = web.SiteGroups.GetByName(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQuery();
                }
            }

            if (SetAssociatedGroup != AssociatedGroupTypeEnum.None)
            {
                switch (SetAssociatedGroup)
                {
                    case AssociatedGroupTypeEnum.Visitors:
                        {
                            web.AssociateDefaultGroups(null, null, group);
                            break;
                        }
                    case AssociatedGroupTypeEnum.Members:
                        {
                            web.AssociateDefaultGroups(null, group, null);
                            break;
                        }
                    case AssociatedGroupTypeEnum.Owners:
                        {
                            web.AssociateDefaultGroups(group, null, null);
                            break;
                        }
                }
            }
            ClientContext.ExecuteQuery();
            WriteObject(group);
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: RMSATS/mattercenter
        /// <summary>
        /// Creates group with restricted access permissions on client site collection to allow functionality in matter landing page
        /// </summary>
        /// <param name="siteUrl">URL of the client site collection to create group at</param>
        /// <param name="onlineCredentials">credentials to access site</param>
        internal static void CreateRestrictedGroup(string siteUrl, SharePointOnlineCredentials onlineCredentials)
        {
            try
            {
                Console.WriteLine("Creating " + ConfigurationManager.AppSettings["restrictedAccessGroupName"] + " group.");

                using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    clientContext.Credentials = onlineCredentials;
                    Site collSite = clientContext.Site;
                    Web site = clientContext.Web;

                    //Create group
                    GroupCollection collGroup = site.SiteGroups;
                    clientContext.Load(collGroup, group => group.Include(properties => properties.Title));
                    clientContext.Load(site.RoleDefinitions);
                    clientContext.ExecuteQuery();

                    Group currentGrp = (from grp in collGroup where grp.Title == ConfigurationManager.AppSettings["restrictedAccessGroupName"] select grp).FirstOrDefault();
                    if (currentGrp != null)
                    {
                        collGroup.Remove(currentGrp);
                    }

                    GroupCreationInformation grpInfo = new GroupCreationInformation();
                    grpInfo.Title = ConfigurationManager.AppSettings["restrictedAccessGroupName"];
                    grpInfo.Description = ConfigurationManager.AppSettings["restrictedAccessGroupDescription"];
                    collGroup.Add(grpInfo);
                    site.Update();
                    clientContext.Load(collGroup);
                    clientContext.ExecuteQuery();

                    currentGrp = (from grp in collGroup where grp.Title == ConfigurationManager.AppSettings["restrictedAccessGroupName"] select grp).FirstOrDefault();

                    AssignPermissionToGroup(clientContext, collSite, site, currentGrp);

                    //Add everyone to group
                    User allUsers = clientContext.Web.EnsureUser(ConfigurationManager.AppSettings["allUsers"]);
                    clientContext.Load(allUsers);
                    clientContext.ExecuteQuery();

                    currentGrp.Users.AddUser(allUsers);
                    site.Update();
                    clientContext.Load(currentGrp);
                    clientContext.ExecuteQuery();

                    Console.WriteLine("Created " + ConfigurationManager.AppSettings["restrictedAccessGroupName"] + " group successfully");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred while creating group: " + exception.Message);
            }
        }
コード例 #28
0
ファイル: NewGroup.cs プロジェクト: veniti/PnP-PowerShell
        protected override void ExecuteCmdlet()
        {
            var web = SelectedWeb;

            var groupCI = new GroupCreationInformation {
                Title = Title, Description = Description
            };

            var group = web.SiteGroups.Add(groupCI);

            ClientContext.Load(group);
            ClientContext.Load(group.Users);
            ClientContext.ExecuteQueryRetry();
            var dirty = false;

            if (AllowRequestToJoinLeave)
            {
                group.AllowRequestToJoinLeave = true;
                dirty = true;
            }

            if (AutoAcceptRequestToJoinLeave)
            {
                group.AutoAcceptRequestToJoinLeave = true;
                dirty = true;
            }
            if (AllowMembersEditMembership)
            {
                group.AllowMembersEditMembership = true;
                dirty = true;
            }
#pragma warning disable 618
            if (OnlyAllowMembersViewMembership)
#pragma warning restore 618
            {
                group.OnlyAllowMembersViewMembership = true;
                dirty = true;
            }
            if (DisallowMembersViewMembership)
            {
                group.OnlyAllowMembersViewMembership = false;
                dirty = true;
            }
            if (!string.IsNullOrEmpty(RequestToJoinEmail))
            {
                group.RequestToJoinLeaveEmailSetting = RequestToJoinEmail;
                dirty = true;
            }

            if (dirty)
            {
                group.Update();
                ClientContext.ExecuteQueryRetry();
            }

            if (!string.IsNullOrEmpty(Owner))
            {
                Principal groupOwner;

                try
                {
                    groupOwner  = web.EnsureUser(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQueryRetry();
                }
                catch
                {
                    groupOwner  = web.SiteGroups.GetByName(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQueryRetry();
                }
            }


#pragma warning disable CS0618 // Type or member is obsolete
            if (SetAssociatedGroup != AssociatedGroupType.None)

            {
                switch (SetAssociatedGroup)
                {
                case AssociatedGroupType.Visitors:
                {
                    web.AssociateDefaultGroups(null, null, group);
                    break;
                }

                case AssociatedGroupType.Members:
                {
                    web.AssociateDefaultGroups(null, group, null);
                    break;
                }

                case AssociatedGroupType.Owners:
                {
                    web.AssociateDefaultGroups(group, null, null);
                    break;
                }
                }
            }
#pragma warning restore CS0618 // Type or member is obsolete

            ClientContext.ExecuteQueryRetry();
            WriteObject(group);
        }
コード例 #29
0
        public virtual void ProvisionGroups(ClientContext ctx, Web web)
        {
            if (GroupCreators == null)
            {
                return;
            }

            var groups = web.SiteGroups;

            ctx.Load(groups, g => g.Include
                         (group => group.Title));
            ctx.ExecuteQueryRetry();

            var existingGroups = new Dictionary <string, Group>();

            foreach (var group in groups)
            {
                existingGroups.Add(group.Title, group);
            }

            var added = false;

            foreach (var key in GroupCreators.Keys)
            {
                if (!existingGroups.ContainsKey(key))
                {
                    OnNotify(ProvisioningNotificationLevels.Verbose, "Creating group " + GroupCreators[key].Title);
                    var groupInfo = new GroupCreationInformation
                    {
                        Title       = GroupCreators[key].Title,
                        Description = GroupCreators[key].Description
                    };
                    GroupCreators[key].Group = web.SiteGroups.Add(groupInfo);
                    ctx.Load(GroupCreators[key].Group);
                    added = true;
                }
                else
                {
                    OnNotify(ProvisioningNotificationLevels.Verbose,
                             "Group " + GroupCreators[key].Title + " exists. Skipping");
                }
            }
            if (added)
            {
                ctx.ExecuteQueryRetry();
            }
            else
            {
                return;
            }

            foreach (var groupCreator in GroupCreators.Values)
            {
                if (groupCreator.Group != null)
                {
                    OnNotify(ProvisioningNotificationLevels.Verbose, "Setting properties for " + groupCreator.Title);
                    groupCreator.Group.AllowMembersEditMembership     = groupCreator.AllowMembersEditMembership;
                    groupCreator.Group.AllowRequestToJoinLeave        = groupCreator.AllowRequestToJoinLeave;
                    groupCreator.Group.AutoAcceptRequestToJoinLeave   = groupCreator.AutoAcceptRequestToJoinLeave;
                    groupCreator.Group.OnlyAllowMembersViewMembership = groupCreator.OnlyAllowMembersViewMembership;
                    groupCreator.Group.Update();
                    ctx.ExecuteQueryRetry();
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// Imports the new groups.
        /// </summary>
        private void ImportNewGroups()
        {
            Console.WriteLine("Import new groups...");
            Logger.AddMessage("import new Groups...");
            GroupCollection groupCollectionOnSourceServer = this.GetAllGroups(this.SourceClientContext);
            GroupCollection groupCollectoinOnTargetServer = this.GetAllGroups(this.TargetClientContext);

            HashSet <string> titlesOfGroupsOnTargetServer = groupCollectoinOnTargetServer.GetAllTitles();

            foreach (var sourceGroup in groupCollectionOnSourceServer)
            {
                if (!titlesOfGroupsOnTargetServer.Contains(sourceGroup.Title))
                {
                    Console.WriteLine("import group '{0}'", sourceGroup.Title);
                    Logger.AddMessage("import group '" + sourceGroup.Title + "'");
                    GroupCreationInformation groupCreationInformation = new GroupCreationInformation();
                    groupCreationInformation.Description = sourceGroup.Description;
                    groupCreationInformation.Title       = sourceGroup.Title;

                    Group targetGroup = groupCollectoinOnTargetServer.Add(groupCreationInformation);

                    try
                    {
                        targetGroup.AllowMembersEditMembership = sourceGroup.AllowMembersEditMembership;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }

                    try
                    {
                        targetGroup.AllowRequestToJoinLeave = sourceGroup.AllowRequestToJoinLeave;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }

                    try
                    {
                        targetGroup.AutoAcceptRequestToJoinLeave = sourceGroup.AutoAcceptRequestToJoinLeave;
                    }
                    catch (PropertyOrFieldNotInitializedException)
                    {
                    }
                }
                else
                {
                    Console.WriteLine("don't have to migrate group with title '{0}'", sourceGroup.Title);
                    Logger.AddMessage("don't have to import group '" + sourceGroup.Title + "'");
                }
            }

            try
            {
                this.TargetClientContext.ExecuteQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during importing new SiteGroups.", e);
                Logger.AddMessage("Exception during importing new SiteGroups. Error = " + e.Message);
                throw new ElementsMigrationException("Exception during importing new SiteGroups.", e);
            }
        }
コード例 #31
0
ファイル: SPDGClientWeb.cs プロジェクト: tillys/SPDG
        public override void AddSiteGroup(string name, SPDGUser owner, SPDGUser defaultUser, string description)
        {
            if (_site.RootWeb.ID != this.ID)
            {
                _site.RootWeb.AddSiteGroup(name, owner, defaultUser, description);
            }
            invalidateSiteGroups();
            GroupCreationInformation groupCreateInformation=new GroupCreationInformation();
            groupCreateInformation.Title = name;
            groupCreateInformation.Description = description;

            var group= _web.SiteGroups.Add(groupCreateInformation);
            group.Owner = ((SPDGClientUser) owner).User;
            group.Update();
            _context.ExecuteQuery();
        }
コード例 #32
0
ファイル: NewGroup.cs プロジェクト: syd2ng/PnP
        protected override void ExecuteCmdlet()
        {
            var web = SelectedWeb;

            var groupCI = new GroupCreationInformation {
                Title = Title, Description = Description
            };

            var group = web.SiteGroups.Add(groupCI);

            ClientContext.Load(group);
            ClientContext.Load(group.Users);
            ClientContext.ExecuteQueryRetry();
            var dirty = false;

            if (AllowRequestToJoinLeave)
            {
                group.AllowRequestToJoinLeave = true;
                dirty = true;
            }

            if (AutoAcceptRequestToJoinLeave)
            {
                group.AutoAcceptRequestToJoinLeave = true;
                dirty = true;
            }
            if (dirty)
            {
                group.Update();
                ClientContext.ExecuteQueryRetry();
            }


            if (!string.IsNullOrEmpty(Owner))
            {
                Principal groupOwner;

                try
                {
                    groupOwner  = web.EnsureUser(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQueryRetry();
                }
                catch
                {
                    groupOwner  = web.SiteGroups.GetByName(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQueryRetry();
                }
            }


            if (SetAssociatedGroup != AssociatedGroupType.None)
            {
                switch (SetAssociatedGroup)
                {
                case AssociatedGroupType.Visitors:
                {
                    web.AssociateDefaultGroups(null, null, group);
                    break;
                }

                case AssociatedGroupType.Members:
                {
                    web.AssociateDefaultGroups(null, group, null);
                    break;
                }

                case AssociatedGroupType.Owners:
                {
                    web.AssociateDefaultGroups(group, null, null);
                    break;
                }
                }
            }
            ClientContext.ExecuteQueryRetry();
            WriteObject(group);
        }
コード例 #33
0
ファイル: RERProjectStatement.svc.cs プロジェクト: nganbui/SP
        /// <summary>
        /// Create group if it's not existed
        /// </summary>
        /// <param name="collGroup"></param>
        /// <param name="groupName"></param>
        /// <param name="oWebsite"></param>
        /// <param name="clientContext"></param>
        /// <param name="roleType"></param>
        /// <param name="users"></param>
        private static void CreateGroup(GroupCollection collGroup, string groupName, Web oWebsite, ClientContext clientContext, RoleType roleType, List<FieldUserValue> users)
        {
            try
            {
                Group grp = collGroup.Where(g => g.Title == groupName).FirstOrDefault();
                oWebsite.BreakRoleInheritance(true, false);
                if (grp == null)
                {
                    GroupCreationInformation groupCreationInfo = new GroupCreationInformation();
                    groupCreationInfo.Title = groupName;
                    groupCreationInfo.Description = "Use this group to grant people " + roleType.ToString() + " permissions to the SharePoint site: " + oWebsite.Title;
                    grp = oWebsite.SiteGroups.Add(groupCreationInfo);
                    //clientContext.Load(grp);
                    //clientContext.ExecuteQuery();
                }
                // grant role to group
                RoleDefinitionBindingCollection collRoleDefinitionBinding = new RoleDefinitionBindingCollection(clientContext);
                RoleDefinition oRoleDefinition = oWebsite.RoleDefinitions.GetByType(roleType);
                collRoleDefinitionBinding.Add(oRoleDefinition);
                oWebsite.RoleAssignments.Add(grp, collRoleDefinitionBinding);
                clientContext.Load(grp, group => group.Title);
                clientContext.Load(oRoleDefinition, role => role.Name);
                clientContext.ExecuteQuery();

                // Add users to newly created group or existing group
                AddUsertoGroup(grp, clientContext, users);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);

            }
        }
コード例 #34
0
        protected override void ExecuteCmdlet()
        {
            var web = SelectedWeb;

            var groupCI = new GroupCreationInformation { Title = Title, Description = Description };

            var group = web.SiteGroups.Add(groupCI);

            ClientContext.Load(group);
            ClientContext.Load(group.Users);
            ClientContext.ExecuteQueryRetry();
            var dirty = false;
            if (AllowRequestToJoinLeave)
            {
                group.AllowRequestToJoinLeave = true;
                dirty = true;
            }

            if (AutoAcceptRequestToJoinLeave)
            {
                group.AutoAcceptRequestToJoinLeave = true;
                dirty = true;
            }
            if (AllowMembersEditMembership)
            {
                group.AllowMembersEditMembership = true;
                dirty = true;
            }
            if (OnlyAllowMembersViewMembership)
            {
                group.OnlyAllowMembersViewMembership = true;
                dirty = true;
            }
            if (!string.IsNullOrEmpty(RequestToJoinEmail))
            {
                group.RequestToJoinLeaveEmailSetting = RequestToJoinEmail;
                dirty = true;
            }

            if (dirty)
            {
                group.Update();
                ClientContext.ExecuteQueryRetry();
            }

            if (!string.IsNullOrEmpty(Owner))
            {
                Principal groupOwner;

                try
                {
                    groupOwner = web.EnsureUser(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQueryRetry();
                }
                catch
                {
                    groupOwner = web.SiteGroups.GetByName(Owner);
                    group.Owner = groupOwner;
                    group.Update();
                    ClientContext.ExecuteQueryRetry();
                }
            }

            if (SetAssociatedGroup != AssociatedGroupType.None)
            {
                switch (SetAssociatedGroup)
                {
                    case AssociatedGroupType.Visitors:
                        {
                            web.AssociateDefaultGroups(null, null, group);
                            break;
                        }
                    case AssociatedGroupType.Members:
                        {
                            web.AssociateDefaultGroups(null, group, null);
                            break;
                        }
                    case AssociatedGroupType.Owners:
                        {
                            web.AssociateDefaultGroups(group, null, null);
                            break;
                        }
                }
            }
            ClientContext.ExecuteQueryRetry();
            WriteObject(group);
        }
コード例 #35
0
ファイル: Class1.cs プロジェクト: aglesaint/sharepointSite
        public string CreateSite(string urlRoot_, string siteUrl_, string title_, string administrator_, XmlDocument params_)
        {

            using (ClientContext ctx = new ClientContext(urlRoot_))
            {
                ctx.Credentials = SelectCreds(params_);
                Web rootWeb = ctx.Web;
                ctx.Load(rootWeb);
                ctx.ExecuteQuery();

                // Site web
                WebCreationInformation wci = new WebCreationInformation();
                wci.Url = siteUrl_;
                wci.Title = title_;
                wci.Language = Convert.ToInt32(params_.DocumentElement.Attributes["Langue"].Value);
                wci.WebTemplate = params_.DocumentElement.Attributes["Template"].Value;
                wci.Description = "";
                wci.UseSamePermissionsAsParentSite = false;
                Web newWeb = ctx.Web.Webs.Add(wci);
               

                // Paramétrage du site
                // Masterpage
                /*         newWeb.MasterUrl = ctx.Web.ServerRelativeUrl + params_.DocumentElement.Attributes["MasterPage"].Value;
                         newWeb.CustomMasterUrl = ctx.Web.ServerRelativeUrl + params_.DocumentElement.Attributes["MasterPage"].Value;
                         // Features à desactiver
                         XmlNode feats = params_.DocumentElement.SelectSingleNode("/CNPCloud/FeaturesToDeactivate");
                         foreach (XmlNode xnf in feats.ChildNodes)
                         {
                             newWeb.Features.Remove(new Guid(xnf.Attributes["Id"].Value), true);
                         }
                 */

                /* 
                 * Groupe administrateur du site en cours 
                 * 
                 */
                  XmlNode groupAdmin = params_.DocumentElement.SelectSingleNode("/CNPCloud/GroupAdmin");
                  GroupCreationInformation gcadmin = new GroupCreationInformation();
                  gcadmin.Title = siteUrl_ + groupAdmin.Attributes["Suffix"].Value;
                  Group gAdmins = newWeb.SiteGroups.Add(gcadmin);
                  gAdmins.Owner = ctx.Web.EnsureUser(params_.DocumentElement.Attributes["SPAdmin"].Value);
                  UserCreationInformation uci = new UserCreationInformation();
                  uci.LoginName = administrator_;
                  gAdmins.Users.Add(uci);
                  gAdmins.Update();
    
                  SetRoleForGroup(ctx, newWeb, gAdmins, groupAdmin.Attributes["Role"].Value);
                  newWeb.AssociatedOwnerGroup = gAdmins;
                  newWeb.Update();

                  /* 
                   * Creation des groupes supplémentaire 
                   * ex: <GroupsToCreate>	
                   *       <Group Suffix="_Collaborateurs" Role="Modification"/>
                   */
                  XmlNode groups = params_.DocumentElement.SelectSingleNode("/CNPCloud/GroupsToCreate");
                     foreach (XmlNode xng in groups.ChildNodes)
                     {
                         GroupCreationInformation gci = new GroupCreationInformation();
                         gci.Title = siteUrl_ + xng.Attributes["Suffix"].Value;
                         Group g = newWeb.SiteGroups.Add(gci);
                         g.Owner = gAdmins;
                         g.Update();
                         SetRoleForGroup(ctx, newWeb, g, xng.Attributes["Role"].Value);
                     }





                     /*
                     GroupCreationInformation gcAdmin = new GroupCreationInformation();
                     gcAdmin.Title = siteUrl_ + "_Admins";
                    gAdmins = newWeb.SiteGroups.Add(gcAdmin);
                     gAdmins.Owner = ctx.Web.EnsureUser(params_.Attributes["SPAdmin"].Value);
                     UserCreationInformation uci = new UserCreationInformation();
                     uci.LoginName = administrator_;
                     gAdmins.Users.Add(uci);
                     gAdmins.Update();
                     SetRoleForGroup(ctx, newWeb, gAdmins, RoleType.WebDesigner);
                     /*
                      // Collab
                      GroupCreationInformation gcCollab = new GroupCreationInformation();
                      gcCollab.Title = siteUrl_ + "_Collaborateurs";
                      Group gCollab = newWeb.SiteGroups.Add(gcCollab);
                      gCollab.Owner = gAdmins;
                      gCollab.Update();
                      SetRoleForGroup(ctx, newWeb, gCollab, RoleType.Contributor);

                      // Lecteur
                      GroupCreationInformation gcVisit = new GroupCreationInformation();
                      gcVisit.Title = siteUrl_ + "_Visiteurs";
                      Group gVisit = newWeb.SiteGroups.Add(gcVisit);
                      gVisit.Owner = gAdmins;
                      gVisit.Update();
                      SetRoleForGroup(ctx, newWeb, gVisit, RoleType.Reader);
                      */


                ctx.ExecuteQuery();

                return "OK";
            }

        }
コード例 #36
0
ファイル: Program.cs プロジェクト: Microsoft/mattercenter
        /// <summary>
        /// Method to check if a group exists and create a new one
        /// </summary>
        /// <param name="collGroup">group collection</param>
        /// <param name="item">data storage</param>
        /// <param name="site">site object</param>
        /// <param name="clientContext">client context</param>
        /// <returns>returns group object</returns>
        private static Group CheckAndCreateGroup(GroupCollection collGroup, DataStorage item, Web site, ClientContext clientContext)
        {
            Group currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();
            if (currentGrp != null)
            {
                Console.WriteLine("Deleting group " + item.GroupName + " as it is already present");
                collGroup.Remove(currentGrp);
            }

            //Creating group
            Console.WriteLine("Creating group " + item.GroupName);
            GroupCreationInformation grpInfo = new GroupCreationInformation();
            grpInfo.Title = item.GroupName;
            grpInfo.Description = item.GroupDesc;
            collGroup.Add(grpInfo);
            site.Update();
            clientContext.Load(collGroup);
            clientContext.ExecuteQuery();
            Console.WriteLine("Successfully created group " + item.GroupName);
            currentGrp = (from grp in collGroup where grp.Title == item.GroupName select grp).FirstOrDefault();
            return currentGrp;
        }