//gavdcodeend 06 //gavdcodebegin 07 static void SpCsCsomCreateGroupForSite(ClientContext spAdminCtx) { string[] myOwners = new string[] { "*****@*****.**" }; GroupCreationParams myGroupParams = new GroupCreationParams(spAdminCtx); myGroupParams.Owners = myOwners; //GroupCreationParams Tenant myTenant = new Tenant(spAdminCtx); myTenant.CreateGroupForSite( ConfigurationManager.AppSettings["spBaseUrl"] + "/sites/NewSiteCollectionModernCsCsom01", "GroupForNewSiteCollectionModernCsCsom01", "GroupForNewSiteCollAlias", true, myGroupParams); spAdminCtx.ExecuteQuery(); }
/// <summary> /// Connect an Office 365 group to an existing SharePoint site collection /// </summary> /// <param name="tenant">The target tenant</param> /// <param name="siteUrl">Url to the site collection that needs to get connected to an Office 365 group</param> /// <param name="siteCollectionGroupifyInformation">Information that configures the "groupify" process</param> public static void GroupifySite(this Tenant tenant, string siteUrl, TeamSiteCollectionGroupifyInformation siteCollectionGroupifyInformation) { if (string.IsNullOrEmpty(siteUrl)) { throw new ArgumentException("Missing value for siteUrl", "siteUrl"); } if (siteCollectionGroupifyInformation == null) { throw new ArgumentException("Missing value for siteCollectionGroupifyInformation", "sitecollectionGroupifyInformation"); } if (!string.IsNullOrEmpty(siteCollectionGroupifyInformation.Alias) && siteCollectionGroupifyInformation.Alias.Contains(" ")) { throw new ArgumentException("Alias cannot contain spaces", "Alias"); } if (string.IsNullOrEmpty(siteCollectionGroupifyInformation.DisplayName)) { throw new ArgumentException("DisplayName is required", "DisplayName"); } GroupCreationParams optionalParams = new GroupCreationParams(tenant.Context); if (!String.IsNullOrEmpty(siteCollectionGroupifyInformation.Description)) { optionalParams.Description = siteCollectionGroupifyInformation.Description; } if (!String.IsNullOrEmpty(siteCollectionGroupifyInformation.Classification)) { optionalParams.Classification = siteCollectionGroupifyInformation.Classification; } if (siteCollectionGroupifyInformation.KeepOldHomePage) { optionalParams.CreationOptions = new string[] { "SharePointKeepOldHomepage" }; } tenant.CreateGroupForSite(siteUrl, siteCollectionGroupifyInformation.DisplayName, siteCollectionGroupifyInformation.Alias, siteCollectionGroupifyInformation.IsPublic, optionalParams); tenant.Context.ExecuteQueryRetry(); }
static void Main(string[] args) { string ClassSiteUrl = "https://xxxx.sharepoint.com/sites/Customsitecol"; string AdminSiteUrl = "https://xxxx-admin.sharepoint.com"; string clientId = "e0cxxxxxxxxxxxxx63112"; //e.g. 01e54f9a-81bc-4dee-b15d-e661ae13f382 string clientSecret = @"AHk8xxxxZIa88QgM7"; string tenantID = "8a400xxxxxxxxxxxxxxxx872cfeef"; var pwd = "xxxxxx"; var username = "******"; var authManager = new AuthenticationManager(); ClientContext context = authManager.GetSharePointOnlineAuthenticatedContextTenant(AdminSiteUrl, username, pwd); Tenant tenant = new Tenant(context); tenant.CreateGroupForSite(ClassSiteUrl, "display-name-for-group", "alias-for-group", true, null); context.ExecuteQuery(); //get group id ClientContext classicalsitectx = authManager.GetSharePointOnlineAuthenticatedContextTenant(ClassSiteUrl, username, pwd); classicalsitectx.Load(classicalsitectx.Site); classicalsitectx.ExecuteQuery(); var groupid = classicalsitectx.Site.GroupId.ToString(); //ea866578-ee7f-48ba-bdbd-9acca12b6da8 // Link group to a team IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder .Create(clientId) .WithTenantId(tenantID) .WithClientSecret(clientSecret) .Build(); ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication); GraphServiceClient graphClient = new GraphServiceClient(authProvider); var team = new Team { MemberSettings = new TeamMemberSettings { AllowCreateUpdateChannels = true, ODataType = null }, MessagingSettings = new TeamMessagingSettings { AllowUserEditMessages = true, AllowUserDeleteMessages = true, ODataType = null }, FunSettings = new TeamFunSettings { AllowGiphy = true, GiphyContentRating = GiphyRatingType.Strict, ODataType = null }, ODataType = null }; var res = graphClient.Groups[groupid].Team.Request().PutAsync(team).Result; Console.WriteLine(res); Console.ReadKey(); }