Creating a Folder in SharePoint From a CRM Plugin

“You should make it so when you create a record, a folder with that name is created,” remarked a sage and wise manager. “Is this possible?”

“Why, yes it is!” was my quick response.

Why Might You Want To Do This?
• Automating/requiring automation of tasks with SharePoint (create a folder, add/update a list, etc.)
• Getting your plugin(CRM) and SharePoint linked/in sync.

How to Create a Folder in SharePoint from a CRM Plugin

Step 1: Add the Required Assembly
In this case, it is just the SharePoint.Client.dll. You can get this bad boy in the “SharePoint Foundation 2010 Client Object Model Redistributable” by visiting http://www.microsoft.com/en-us/download/details.aspx?id=21786

Don’t forget to include it in your project:

Create a Folder in SharePoint from a CRM Plugin

Also, don’t forget to add the “using” line to your plugin’s cs file:

Create a Folder in SharePoint from a CRM Plugin

Step 2: Connect to SharePoint

Create a Folder in SharePoint from a CRM Plugin

In the snippet, above I’ve commented out an additional line:

// context.Credentials = new NetworkCredentials(“Administrator”, “pass@word1”);

(Use this line if you don’t want to use the default credentials and want to specify the account talking to SharePoint laugh)

Step 3: Check to See if the Folder Already Exists (sorta optional)

You can accomplish this by creating a function, and then calling it in an “if” statement like so:

Create a Folder in SharePoint from a CRM Plugin

In this case, GetFolderCI is the function used to check if the folder is already there or not. The listTitle variable is the next level up from the folder you are looking for (the doc library a level up from the folder).

Create a Folder in SharePoint from a CRM Plugin

The following function will return the folder (if it exists). Inside this function, it calls another to actually check for the title.

Create a Folder in SharePoint from a CRM Plugin

This function queries the document library for the folder and returns any results.

Step 4: Create Folder

In the “if” statement above, if no result is returned, a function called “CreateFolder” is called (passing the same values as the “check if folder exists” function.)

Create a Folder in SharePoint from a CRM Plugin

And there you have it! After running this, you will have successfully created a folder in SharePoint!

Phone: 312-602-4000
Email: marketing@westmonroepartners.com
222 W. Adams
Chicago, IL 60606
Show Buttons
Share On Facebook
Share On Twitter
Share on LinkedIn
Hide Buttons