Create SharePoint folders via CRM Plugin RRS feed

  • Question

  • Hello,

    I'm enabling integration from CRM 2013 (RU1 SP1 On-Premises) to SharePoint 2013, but I need to create the folders on SharePoint automatically when a new record is added to the Entity in CRM since we will be adding documents to this folder through other means outside of CRM.  The documentation mentions this:


    Creating and managing SharePoint document location records. Microsoft Dynamics CRM users can create and manage SharePoint Server document location records after SharePoint Server integration is enabled. You can create and manage SharePoint Server document location records by using the SharePointDocumentLocation entity. Microsoft Dynamics CRM also allows for the automatic creation of folders on the server that is running SharePoint Server for entity records under certain conditions. However, automatic creation of folders cannot be done through the Microsoft Dynamics CRM SDK.

    Since I can't add folders through the SDK, if I added the SharePoint client/runtime to the Plugin and created them directly in SharePoint is there anyway to mark these as being created in CRM?  Or alternatively if I created a small file through CRM for the new record on the entity would the folder in SharePoint be created for this file?  If so I could use this to verify the folder is created then just delete the file.

    Thanks ..

    Thursday, June 11, 2015 1:09 PM

All replies

  • Hi,

    Below are few pointers to achieve this.

    1.Enable OOB SharePoint Integration with CRM.

    2.Create a Service(Web API) which handles the folder  creation in sharepoint .

    3.Deploy this Web API in SharePoint Server.

    4.Call that Web API in your plugin and pass the necessary parameters required, for example entity name,ID.



    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Thursday, June 11, 2015 6:10 PM
  • Hi,

    You can use plugin to create folder in sharepoint

    For that you need to add Microsoft.SharePoint.Client dll into your crm  server then register your plugin on creation of record 

    Refer bellow code to get an idea

    //params:subfolder:on which name you want to create;
    //mainfoler:entity name
    public string CreateSharePointFolder(string sharepointsite, string crmusername, string crmpassword, string mainfolder, string subfolder)
                string status = string.Empty;
                if (string.IsNullOrEmpty(sharepointsite) || string.IsNullOrEmpty(crmusername) || string.IsNullOrEmpty(crmpassword) || string.IsNullOrEmpty(mainfolder) || string.IsNullOrEmpty(subfolder))
                    return string.Empty;
                    using (ClientContext clientContext = new ClientContext(sharepointsite))
                        SecureString passWord = new SecureString();
                        foreach (char c in crmpassword.ToCharArray()) passWord.AppendChar(c);
                        clientContext.Credentials = new SharePointOnlineCredentials(crmusername, passWord);
                        var folder = CreateFolder(clientContext.Web, mainfolder, subfolder);
                        status = folder != null ? folder.Name :string.Empty;
                catch (Exception ex)
                    return ex.Message;
                return status;
            private Folder CreateFolder(Web web, string listTitle, string fullFolderUrl)
                if (string.IsNullOrEmpty(fullFolderUrl))
                    throw new ArgumentNullException("fullFolderUrl");
                var list = web.Lists.GetByTitle(listTitle);
                if (list == null)
                    return null;
                var curFolder = list.RootFolder.Folders.Add(fullFolderUrl.ToString());
                return curFolder;

    • Proposed as answer by Ashok Jinkala Thursday, October 1, 2015 11:26 AM
    • Edited by Ashok Jinkala Monday, October 12, 2015 11:52 AM
    Wednesday, June 24, 2015 5:49 AM