Tuesday, April 18, 2017

Create site collection using CSOM

                string userName = WebConfigurationManager.AppSettings.Get("UserName");
                string password = WebConfigurationManager.AppSettings.Get("Password");
                string domain = WebConfigurationManager.AppSettings.Get("Domain");

                using (var ctx = new ClientContext("http://siteUrl/"))
                {
                    ctx.Credentials = new System.Net.NetworkCredential(userName, password, domain);
                    ctx.RequestTimeout = Timeout.Infinite;

                    var tenant = new Tenant(ctx);
                    var properties = new SiteCreationProperties()
                    {
                        Url = "http://siteUrl/sites/site1",
                        Owner = string.Format("{0}\\{1}",domain,userName),
                        Title = "Test Site",
                        Template = "STS#0"
                    };

                    SpoOperation op = tenant.CreateSite(properties);
                    ctx.Load(op, i => i.IsComplete);
                    ctx.ExecuteQuery();
                }

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...