Beispiel #1
0
        // 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
Beispiel #2
0
        // Method to Call for SharePoint Site Lists - onInitialise Window
        public void GetSiteLists(string Url)
        {
            var spoL = new SPOLogic(Url);
            IEnumerable <Microsoft.SharePoint.Client.List> lists = spoL.getWebLists(Url, CredManager).Where(l => !l.Hidden);

            //LBLists.Items.Clear();
            foreach (Microsoft.SharePoint.Client.List lst in lists)
            {
                //LBLists.Items.Add(lst.Title + " - (" + lst.ItemCount + ")");
            }
        }// End Method
Beispiel #3
0
        }// End Method

        // Method - Refresh.onClick() - Call for showsite
        private void RefreshSites(object sender, RoutedEventArgs e)
        {
            SPOLogic sp = new SPOLogic(CredManager);

            // Task - SetTenantProps and show sites
            Task.Factory.StartNew(() =>
            {
                this.TenantProp = sp.getTenantProp(CredManager);
                ShowSites();
            });

            //Clear Ui
            TBOut.Content = "";
            SiteView.Items.Clear();
        }// End Method
Beispiel #4
0
        }// End Constructor

        // Method - Window.Loaded() - Set TenantProps & Show Sites to Treeview
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SPOLogic sp = new SPOLogic(CredManager);

            // Task - SetTenantProps

            this.TenantProp = sp.getTenantProp(CredManager);
            if (this.TenantProp == null)
            {
                new MainWindow().Show();
                this.Hide();
            }
            else
            {
                ShowSites();
            }
        }// End Method
Beispiel #5
0
        }// End Method

        #endregion


        // Method to Call for SharePoint Site Props (Title and SiteUsers) - Task()
        private void GetSiteProps(string Url)
        {
            var spoL = new SPOLogic(Url);
            Web web  = spoL.getWebProps(Url, CredManager);

            // Pushing SiteName, Admin count and Admin.Title to TBOut
            TBOut.Content  = "SiteName : " + web.Title + Environment.NewLine;
            TBOut.Content += "BaseTemplate : " + web.WebTemplate + "#" + web.Configuration.ToString() + Environment.NewLine;
            TBOut.Content += "Admin count : " + web.SiteUsers.Where(u => u.IsSiteAdmin).Count() + Environment.NewLine;

            var admins = web.SiteUsers.Where(u => u.IsSiteAdmin);

            foreach (var admin in admins)
            {
                TBOut.Content += admin.Title + Environment.NewLine;
            }
        }// End Method
Beispiel #6
0
        }// 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
Beispiel #7
0
        }// End Method

        // Method - TreeViewItem.Expand Listener - Call for Site Lists
        private void Folder_Expanded(object sender, RoutedEventArgs e)
        {
            var item = (TreeViewItem)sender;

            // If the item only contains the dumy data
            if (item.Items.Count != 1 || item.Items == null)
            {
                return;
            }
            //Clear dummy item
            item.Items.Clear();

            // Get Site library
            var SitePath = (string)item.Tag;

            Task.Factory.StartNew(() =>
            {
                // Call for the expended site Web
                var spoL = new SPOLogic(CredManager);
                // Filter on not hidden file
                IEnumerable <Microsoft.SharePoint.Client.List> lists = spoL.getWebLists(SitePath, CredManager).Where(l => !l.Hidden);

                item.Dispatcher.Invoke(() =>
                {
                    // Creating TreeeViewIems from lists
                    foreach (var list in lists)
                    {
                        var subitem = new TreeViewItem
                        {
                            Header = list.Title + " (" + list.ItemCount + ") - " + list.BaseTemplate.ToString(),
                            Tag    = list.BaseTemplate.ToString(),
                        };

                        item.Items.Add(subitem);
                    }
                }); // End Dispatch
            });     // End Task
        }// End Method
Beispiel #8
0
        }// 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