-
Notifications
You must be signed in to change notification settings - Fork 2
SharePoint CSOM connector
SharePoint CSOM connector is a SPCoder module that can be used to connect to SharePoint On-Premise or SharePoint Online site collection and to show its structure (Subwebs, Lists, Libraries) in SPCoder's Explorerview.
You can connect to SharePoint site collection using SharePoint CSOM connector by entering the url to Explorerview address field, choosing one of the proposed ways for authentication and clicking the Connect button.
The other way to connect to a SharePoint site collection is by calling the main.Connect
method:
main.Connect("SP-Online-site-url", "SharePoint Client O365", "sponlineemail", "sponlinepass");
//Instead of clear text version of "sponlinepass" you can use the "Crypto helper" window to encrypt the password, and then use the encripted value, like this:
main.Connect("SP-Online-site-url", "SharePoint Client O365", "sponlineemail", main.Decrypt("encryptedsponlinepass"));
//This will connect to SharePoint online using the App permissions. ClientId and ClientSecret will be taken from app.config file (SPCoder.exe.config)
main.Connect("SP-Online-site-url", "SharePoint Client O365 APP");
//you can also pass the ClientId and ClientSecret as parameters instead of username/password
main.Connect("SP-Online-site-url", "SharePoint Client O365 APP", "Your-ClientId", "Your-ClientSecret");
//You can use the same encription method shown in previous example if you need to save the clientid/clientsecret in your source code file
//For SharePoint On-Premise you can use the following values
//Windows authentication
main.Connect("SP-On-Premise-site-url", "SharePoint Client WIN", "ADusername", "ADPass");
//FBA authentication
main.Connect("SP-On-Premise-site-url", "SharePoint Client FBA", "FBAusername", "FBAPass");
After the connection is made, SPCoder will add the Site collection object, Web object and ClientContext object to the Context window and name the variables site
, web
and context
(In case a variable with the same name already exists, it will append the number to the name, similar to site1
or site2
)
You can also add any list/library/subsite to the context simply by dragging and dropping them from Explorerview to Context window.
You can then write your code to manipulate data in SharePoint:
context.Load(web, w => w.Url);
context.ExecuteQuery();
var coronaList = web.GetList(web.Url + "/Lists/Corona");
context.Load(coronaList);
context.ExecuteQuery();
CamlQuery query = CamlQuery.CreateAllItemsQuery();
var coronaItems = coronaList.GetItems(query);
coronaList.Context.Load(coronaItems, its => its.Include(item => item["ID"],
item => item["TotalCases"],
item => item["Title"]) );
context.ExecuteQuery();
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
- Refresh - gets the latest site structure from the server and recreates the tree view
- 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
- Get PnP provisioning template xml - generates the PnP provisioning template xml and displays it in code editor - This item was added using a plugin
- List or library
- Open in browser - opens the SP site collection in browser
- Copy link - copies the link to SP site collection to clipboard
- Show items in grid - gets all the elements from selected list and shows them in GridViewer This item was added using a plugin
You can use SharePoint CSOM connector to connect to SharePoint on-premise 2010, 2013, 2016, 2019 and SharePoint Online. SPCoder uses the latest nuget version of CSOM library provided by Microsoft.