// Method - Btn.Click - Connect to SPO Site and retrive Basics Information private void ConnectSPO(object sender, RoutedEventArgs e) { //Using ClientContext - Retrive Basic Informaiton var spoL = new SPOLogic(CredManager); using (ClientContext ctx = spoL.GetSiteContext(TBSite.Text)) { // Calling to Web.Title, Lists and Admins ctx.Load(ctx.Web, w => w.Title, w => w.Lists, w => w.AssociatedOwnerGroup.Users); ctx.ExecuteQueryRetry(); // Showing results to TBOut - Title TBOut.Text = "Site Name : " + ctx.Web.Title + Environment.NewLine; // Showing results to TBOut - Admins Count var admin = ctx.Web.AssociatedOwnerGroup.Users; TBOut.Text += string.Format("Amount of Admin : {0}", admin.Count() + Environment.NewLine); // Showing results to TBOut - Admin Title foreach (var adm in admin) { TBOut.Text += adm.Title + Environment.NewLine; } // Showing results to TBOut - Lists Count TBOut.Text += "Amount of lists : " + ctx.Web.Lists.Count().ToString() + Environment.NewLine; // Showing results to TBOut - List Title foreach (var list in ctx.Web.Lists) { TBOut.Text += list.Title + Environment.NewLine; } } }// End Method
}// End Method // Method - BTN.Click - Create List private void CreateList(object sender, RoutedEventArgs e) { //Using ClientContext - Retrive Basic Informaiton var spoL = new SPOLogic(CredManager); using (ClientContext ctx = spoL.GetSiteContext(TBSite.Text)) { try { //Attempt to create the list ctx.Web.CreateList(ListTemplateType.DocumentLibrary, TBList.Text, false); MessageBox.Show(string.Format("List : {0} has been created in SPOSite : {1}", TBList.Text, TBSite.Text)); } catch (Exception ex) { MessageBox.Show(string.Format("Unable to create list : {0}" + Environment.NewLine + "{1}", TBList.Text, ex.Message)); } } }// End Methodok
}// End Method #endregion #region Site Creation //Method to create a Modern Project / Communication Site private async void createSite(string SiteTemplate) { if (string.IsNullOrEmpty(TBSiteName.Text)) { MessageBox.Show("Please give a site name", "My app", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var spoL = new SPOLogic(CredManager); ClientContext ctx = spoL.GetSiteContext(CredManager); if (SiteTemplate == "Team") { var sitecontext = await ctx.CreateSiteAsync(new TeamSiteCollectionCreationInformation { Description = "", DisplayName = TBSiteName.Text, Alias = TBSiteName.Text, IsPublic = true, //Classification="IT" }); } else { var communicationContext = await ctx.CreateSiteAsync(new CommunicationSiteCollectionCreationInformation { Title = TBSiteName.Text, // Mandatory Description = "", // Mandatory Lcid = 1033, // Mandatory //AllowFileSharingForGuestUsers = false, // Optional //Classification = "classification", // Optional SiteDesign = CommunicationSiteDesign.Topic, // Mandatory Url = "https://toanan.sharepoint.com/sites/" + TBSiteName.Text, // Mandatory }); } ctx.Dispose(); }// End Method