Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to access a remote site using SP.RemoteWeb and Javascript - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2015-10-02

In this post, we will see how to access a different site/web objects from the Personal / PointPublishing site. Office 365 and SharePoint 2016 now 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://<<>>.sharepoint.com/portals/personal/<username>

Get the Remote Web:

var remoteWeb = new SP.RemoteWeb(context,"https://domain.sharepoint.com");
context.load(remoteWeb);
context.executeQueryAsync(function(){},function(){});
  • The above script retrieves the remoteWeb of the root web of the main site collection.
    • ex: https://domain.sharepoint.com

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
(Visited 335 times, 1 visits today)

About the author 

Balamurugan Kailasam

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.