csharp Criando SiteCollection e Lista没有SharePoint Online通过CSOM / C#。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Criando SiteCollection e Lista没有SharePoint Online通过CSOM / C#。相关的知识,希望对你有一定的参考价值。

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Client;
using Microsoft.Online.SharePoint.TenantAdministration;
using System.Security;

//Microsoft.SharePoint.Client.Runtime.dll
//Microsoft.Online.SharePoint.Client.Tenant.dll

public class Create()
{
  public void CreateSite()
  {
    SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                //please change the value of user name, password, and admin portal URL
                string username = "caiobsouza@caiobsouza.onmicrosoft.com";
                String password = "P@ssw0rd";
                string siteTitle = SiteName.Text;


                ClientContext CentralAdminContext = new ClientContext("https://caiobsouza-admin.sharepoint.com");
                SecureString SecurePassword = new SecureString();
                foreach (char c in password.ToCharArray())
                {
                    SecurePassword.AppendChar(c);
                }
                CentralAdminContext.Credentials = new SharePointOnlineCredentials(username, SecurePassword);

                Tenant adminTenant = new Tenant(CentralAdminContext);
                CentralAdminContext.ExecuteQuery();//login into SharePoint online

                //code to create a new site collection

                string newSiteUrl = "https://caiobsouza.sharepoint.com/sites/ti";
                string newSiteOwner = "caiobsouza@caiobsouza.onmicrosoft.com";
                
                var newsite = new SiteCreationProperties()
                {
                    Url = newSiteUrl,
                    Owner = newSiteOwner,
                    Template = "STS#0", //using the team site template, check the MSDN if you want to use other template
                    StorageMaximumLevel = 100,
                    UserCodeMaximumLevel = 100,
                    UserCodeWarningLevel = 100,
                    StorageWarningLevel = 300,
                    Title = siteTitle,
                    CompatibilityLevel = 15, //15 means Shapoint online 2013, 14 means Sharepoint online 2010

                };
                adminTenant.CreateSite(newsite);

                CentralAdminContext.ExecuteQuery();
                //end 

            });
  }
  
  public void CreateList()
  {
    SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                //please change the value of user name, password, and admin portal URL
                string username = "caiobsouza@caiobsouza.onmicrosoft.com";
                String password = "P@ssw0rd";
                string urlWeb = SiteUrl.Text;
                string listTitle = ListName.Text;

                ClientContext context = new ClientContext(urlWeb);
                SecureString SecurePassword = new SecureString();
                foreach (char c in password.ToCharArray())
                {
                    SecurePassword.AppendChar(c);
                }
                context.Credentials = new SharePointOnlineCredentials(username, SecurePassword);
                context.ExecuteQuery();

                Web web = context.Web;

                var newList = new ListCreationInformation()
                {
                    Title = listTitle,
                    TemplateType = (int)ListTemplateType.DocumentLibrary
                };

                web.Lists.Add(newList);
                context.ExecuteQuery();
            });
  }
}

以上是关于csharp Criando SiteCollection e Lista没有SharePoint Online通过CSOM / C#。的主要内容,如果未能解决你的问题,请参考以下文章

text Criando Tipo查询没有graphql

javascript criando下标graphql

php Criando suas没有Codeigniter

powershell Criando服务申请做国家服务

text Criando tipo enum没有graphql

javascript Criando变异e解析器graphql