Skip to content

SharePoint SSOM connector

tomdam edited this page Jun 17, 2020 · 1 revision

SharePoint SSOM connector is a SPCoder module that can be used to connect to SharePoint On-Premise site collection and to show its structure (Subwebs, Lists, Libraries) in SPCoder's Explorerview. In order for this connector to be used, you have to run SPCoder on a machine that is part of SharePoint farm.

Connecting

You can connect to SharePoint site collection using SharePoint SSOM connector by entering the url to Explorerview address field, choosing "SharePoint Server Side" from combo box and clicking the Connect button.

The other way to connect to a SharePoint site collection is by calling the main.Connect method:

main.Connect("http://sp2013/", "SharePoint Server Side");

SSOM connector 1

Usage

After the connection is made, you should drag the objects you need to work with from the Explorerview to the Context window (site/lists/libraries/subwebs).

SSOM connector2

You can then write your code to manipulate data in SharePoint:

//Example 1: write titles of all list items to Output
foreach( SPListItem item in list.Items)
{
    println(item["Title"]);
}

//Example 2:
//Get all SharePoint 2013 Workflow subscriptions for SPWeb object
//In order to use this, add this #r directive to the top of SPCoderImports.csx file:
//#r "Microsoft.SharePoint.WorkflowServicesBase"

var wsm           = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(web);
var subscriptions = wsm.GetWorkflowSubscriptionService().EnumerateSubscriptions();
foreach(var s in subscriptions)
{
    println(s.Name);
}  
//Example 3:
//Display all subsites of site collection in output window:
void PrintSubSites(SPWeb web, string ident)
{
    println(ident + web.Title);
    foreach (SPWeb subweb in web.Webs)
    {
        PrintSubSites(subweb, ident+"    ");
    }
}

PrintSubSites(web, "");

Important note: When working with SharePoint Server Side Object Model (SSOM) you need to execute the code synchronously. Make sure that the option Code -> Asynchronous code execution is unchecked.

Async code execution

If you execute code asynchronously, and you try to work with SharePoint objects, you will get the following error:

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{Some GUID}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).

Actions

SPCoder Explorerview shows the context menu when an item is clicked with right mouse button. When you right-click on an item added by SharePoint CSOM connector, the following menu actions are available:

  • Site
    • Open in browser - opens the SP site collection in browser
    • Copy link - copies the link to SP site collection to clipboard
    • Close - removes the site from tree view and removes any automatically added objects from Context window
  • Web
    • Open in browser - opens the SP site in browser
    • Copy link - copies the link to SP site to clipboard
    • Refresh - gets the latest site structure from the server and recreates the tree view under it
  • List or library
    • Open in browser - opens the SP site collection in browser
    • Copy link - copies the link to SP site collection to clipboard

Supported versions

You can use SharePoint SSOM connector to connect to SharePoint on-premise 2013, 2016, 2019.