May 18 2017 04:46 AM
Has anyone had any luck changing the SiteCollection url in SharePoint Online using CSOM?
Here's a code sample (using OfficedDevPnP extensions)
var tenant = new Tenant(context); var siteProperties = tenant.GetSitePropertiesByUrl("<CurrentUrl>", false); tenant.Context.Load(siteProperties); tenant.Context.ExecuteQueryRetry(); siteProperties.NewUrl = "<NewUrl>"; siteProperties.Update(); tenant.Context.ExecuteQueryRetry();
I get an ArgumentException with the following message
The requested operation is not supported for site: <SiteUrl>
May 18 2017 05:11 AM
what is the context when you add
var tenant=tenant(context) ??
May 18 2017 05:29 AM
It is the Tenant Admin context.
Eg. <myurl>-admin.sharepoint.com
May 18 2017 10:40 AM
Is this something new? So far this has not been supported...adding @VesaJuvonen to comment on this
May 18 2017 11:26 AM
Well, it was added to CSOM a year ago, so I just assumed it was supported by now.
https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-march-2016
The property also exists in the SharePoint Online documentation.
May 18 2017 01:17 PM
how do you build the context with creds etc?
a example of mine
SharePointService sharePointService = new SharePointService(); AuthenticationManager authenticationManager = new AuthenticationManager(); using ( ClientContext adminContext = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant(Info.TenantAdminUri.AbsoluteUri, Info.UserName, Info.UserPassWord)) { adminContext.RequestTimeout = Timeout.Infinite; }
hope it helps
May 18 2017 11:26 PM
I've tried both AppOnly context with full SiteCollection permissions and SharePointOnlineContext.
Neither works.
I can however create/delete sitecollections and change other properties, but NewUrl doesn't work. So I believe my context is ok.
@Deleted you're saying that it works for you? My ServerLibraryVersion is 16.0.6511.1201.
May 19 2017 03:05 AM
Hi I am just checking your code.
What are you trying to accomplish?
Since i see you get the url then want to update the url??
That will not work.
May 19 2017 03:29 AM
Yes, I want to update the url. I'm creating a "buffer" of site collections and want to give them a proper url when they're taken into use.
If that doesn't work, then what is the usage of NewUrl?
Why is it available? Is it because is only works on premises?
May 19 2017 03:37 AM
Hi @Michael Schau,
I just tried this with PnP PowerShell/CSOM and I'm finding the same results as you.
I had a bit of a further play with this where I tried setting NewUrl to ServerRelativeUrls or just setting it to the site specific part of the Url but this gave me just different errors. I would expect that as you can only update the site specific bit that you might not include the full url, but unfortenately that didn't work.
I thnk you might be right that this only works in on premises environments.
May 19 2017 04:37 AM
have you read this?
public property Microsoft.Online.SharePoint.TenantAdministration.SiteProperties.NewUrl - The new URL for the site (updating this will trigger a site rename). Notice. This is not yet functional in the production when this blog post was written
https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-march-2016
May 19 2017 04:44 AM
Hi @Deleted,
I tried this:
$site = Get-PnPTenantSite https://Mytenant.sharepoint.com/sites/testsite
$site.NewUrl = "https://Mytenant.sharepoint.com/sites/testsite2"
$site.Update()
$site.Context.ExecuteQuery()
and then I tried all variations of Urls for the $site.NewUrl = ""
May 19 2017 04:44 AM
Yep, I've read it.
But as mentioned it was posted more than a year ago. Just assumed that it was funtioning in "Production" by now.
May 19 2017 05:24 AM
Just checked with reflector code is implemented but can not debug it 😞