0
votes

I'm new to Office 365 and SharePoint, while I'm trying to create a SharePoint site using CSOM in .NET I've used Tenant like (var tenant = new Tenant(clientContext);) can someone explain what "Tenant" exactly is and what is the use of it in here. When I searched for it I learnt something like Tenant ID which Unique for each Company, but Tenant ID and Tenant in CSOM is different right? and also What is ClientContext? in my code I have used both ClientContext and Tenant to create a SharePoint Site.

using System;
using System.Security;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
namespace CreateSiteCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Program Started!");
            //Opens the Admin URL
            using(ClientContext tenantContext=new ClientContext("https://developer19-admin.sharepoint.com/"))
            {
                //Authenticating with Tenant Admin
                SecureString passWord = new SecureString();
                foreach (char c in "passCode1".ToCharArray())
                    passWord.AppendChar(c);
                tenantContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);

                var tenant = new Tenant(tenantContext);

                //Properties
                var siteCreationProperties = new SiteCreationProperties();

                //New-Site URL
                siteCreationProperties.Url = "https://developer19.sharepoint.com/sites/codesite";

                //Titie of the Root Site
                siteCreationProperties.Title = "Coded Site";

                //Login Name
                siteCreationProperties.Owner = "[email protected]";

                //Template Copied from Team Site
                siteCreationProperties.Template = "STS#0";

                //Storage Limit in MB
                siteCreationProperties.StorageMaximumLevel = 100;

                //UserCode resourse Points Allowed
                siteCreationProperties.UserCodeMaximumLevel = 50;

                //Creates Site Collection
                SpoOperation spo = tenant.CreateSite(siteCreationProperties);

                tenantContext.Load(tenant);

                //IsComplete to check if provisioning is Completed
                tenantContext.Load(spo, i => i.IsComplete);

                tenantContext.ExecuteQuery();

                while(!spo.IsComplete)
                    {
                    //Waits 30 Sec and tries again
                    System.Threading.Thread.Sleep(30000);
                    spo.RefreshLoad();
                    tenantContext.ExecuteQuery();
                }
                Console.WriteLine("SiteCollection Created.");
            }
        }
    }
}
1

1 Answers

1
votes

A Tenant is the Organisation or the Company. It's the "instance of Office 365" that is unique to your user base.

While it's not necessarily a single domain name, because a Tenant could have multiple domain names, that's one way to think of it.

A tenancy in Office 365 refers to the full Office 365 suite attached to a domain. When Office 365 is set up, it creates a tenancy to store all the data for Office 365 including things like SharePoint, OneDrive and Yammer. This allows all of your organisations data to sit in the same environment and be moved around within the tenant with ease.