Monday, October 5, 2015

SP2016 - O365 - SP.RemoteWeb - Access Remote Site - Remote Web from MySite web

In this post, we will see how to access a different site/web objects from the Personal / PointPublishing site. O365 and SP2016 has a new api SP.RemoteWeb which will allow us to access another site / web objects from a different site context.

Get the Current Web:



var context = SP.ClientContext.get_current()var sourceWeb = context.get_web();context.load(sourceWeb);
var targetSite = context.get_site();
context.load(targetSite);
context.executeQueryAsync(function(){},function(){});
  • The above script gets the current context and web for the PointPublishing Personal site.
  • The host context web should be a Personal / Point Publishing site.
    • ex: http://ift.tt/1Pf1BMK;

Get the Remote Web:

var remoteWeb = new SP.RemoteWeb(context,"http://ift.tt/1hy0RDV");
context.load(remoteWeb); context.executeQueryAsync(function(){},function(){});
  • The above script retrieves the remoteWeb of the root web of the main site collection.

Get the Remote Web Folder:

var rFolder = remoteWeb.getFolderByServerRelativeUrl("sitepages");
context.load(rFolder);
context.executeQueryAsync(function(){alert(rFolder.Name)},function(){});
  • The above script retrieves the "sitepages" document library root folder using the remote web from the different site collection.

The equivalent CSOM api is also available on Microsoft.SharePoint.Client.RemoteWeb and it has the following methods.

  • GetFileByServerRelativeUrl
  • GetFolderByServerRelativeUrl
  • GetGroupById
  • GetListById
  • GetListByServerRelativeUrl

by Balamurugan Kailasam via Everyone's Blog Posts - SharePoint Community

No comments:

Post a Comment