“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:
Also, don’t forget to add the “using” line to your plugin’s cs file:
Step 2: Connect to SharePoint
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 )
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:
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).
The following function will return the folder (if it exists). Inside this function, it calls another to actually check for the title.
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.)
And there you have it! After running this, you will have successfully created a folder in SharePoint!