Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Access Denied when programmatically creating site collection

$
0
0

I'm the global administrator and can successfully create site collections through the admin site in office 365 but when I try to create a site with the code below I get an Access Denied error. Any ideas?

 using (ClientContext ctx = new ClientContext("https://tenant-admin.sharepoint.com"))
            {
                ctx.Credentials = new SharePointOnlineCredentials("username", GetPassword()); 

try
                    {

 Tenant _tenant = new Tenant(ctx);
                        var _newsite = new SiteCreationProperties();
                        _newsite.Title = siteRequest.Title;
                        _newsite.Url = siteRequest.Url;
                        _newsite.Owner = siteRequest.SiteOwner.Name;
                        _newsite.Template = template.RootTemplate;
                        _newsite.Lcid = siteRequest.Lcid;
                        _newsite.TimeZoneId = siteRequest.TimeZoneId;

                        SpoOperation op = _tenant.CreateSite(_newsite);
                        ctx.Load(_tenant);
                        ctx.Load(op, i => i.IsComplete);

ctx.ExecuteQuery(); --> This is where the access denied error occurs.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>