Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SharePoint Integration with MS CRM 365

(1) ShareShare
ReportReport
Posted on by 50

Hi,

I am using MS CRM 365 online, working on the integration MS CRM with SharePoint. 

I am able to create the folder in the sharepoint using custom action, is there a way we can check if the folder is already created in the sharepoint ?

1. is it necessry to create the DocumentLocation folder in CRM first before uploading the file to share point ?(Automatic doucmentLocation creation is enabled in CRM during SharePoint integration)

 I tested directly creating the folder in sharepoint through code and uploading the file manually, it seems to be working fine. 

currently I am using below code to create the folder : This code is working without any issue.  I need something similar to check if the folder is already created in the Sharepoint.

public void CreateFolder(string siteUrl, string relativePath)
{

if (siteUrl != _siteUrl)
{
_siteUrl = siteUrl;
Uri spSite = new Uri(siteUrl);

_spo = SpoAuthUtility.Create(spSite, _username, WebUtility.HtmlEncode(_password), false);
}

string odataQuery = "_api/web/folders";

byte[] content = ASCIIEncoding.ASCII.GetBytes(@"{ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '" + relativePath + "'}");


string digest = _spo.GetRequestDigest();

Uri url = new Uri(String.Format("{0}/{1}", _spo.SiteUrl, odataQuery));
// Set X-RequestDigest
var webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webRequest.Headers.Add("X-RequestDigest", digest);

// Send a json odata request to SPO rest services to fetch all list items for the list.
byte[] result = HttpHelper.SendODataJsonRequest(
url,
"POST", // reading data from SP through the rest api usually uses the GET verb
content,
webRequest,
_spo // pass in the helper object that allows us to make authenticated calls to SPO rest services
);

string response = Encoding.UTF8.GetString(result, 0, result.Length);

}

 

*This post is locked for comments

  • Pradeep47 Profile Picture
    Pradeep47 50 on at
    RE: SharePoint Integration with MS CRM 365

    Thanks John

  • Verified answer
    John Clark Profile Picture
    John Clark 400 on at
    RE: SharePoint Integration with MS CRM 365

    Hi Pradeep,

    The SharePointDocumentLocation records are effectively pointers to the folders in SharePoint. When a record (account, opportunity, quote, etc) is renamed, the SharePointDocumentLocation still points to the same folder in SharePoint, which does not get renamed.

    Even with automatic creation of the SharePointDocumentLocation records enabled, they are only created when the first user goes to the Documents tab for that record. So, if you are creating the folders in SharePoint via code you would also need to create an associated SharePointDocumentLocation record, if one does not already exist.

    The approach I've often taken with clients is to add a plug-in that always creates the SharePointDocumentLocation and matching SharePoint folders, when, for example a new account or opportunity is created. The code also needs to handle the situation where a lead has been qualified, potentially resulting in both the creation of an account and opportunity at about the same time. You would also need to create the intermediate folders, such as "opportunity", "quote", if you are using the hierarchical filing.

    Cheers,

    John

  • Pradeep47 Profile Picture
    Pradeep47 50 on at
    RE: SharePoint Integration with MS CRM 365

    Thanks,

    while doing the Sharepoint integration , do we need to create the documentlocation record in the CRM that would autotmatically create the folder in sharepoint ?

    or can we directly create folder in SharePoint (with CRM record name and _GUID)and upload the file into that.

    it leads me to other question what if the user changes the record name in CRM will sharepoint folder name gets updated to same name ? or this creates new folder name with same GUID ?

  • Suggested answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: SharePoint Integration with MS CRM 365

    Look at the documentation:

    [View:https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest:750:50]

    Basically you will have to make the following call:

    url: http://site url/_api/web/GetFolderByServerRelativeUrl('/your folder path')
    method: GET
    headers:
        Authorization: "Bearer " + accessToken
        accept: "application/json;odata=verbose" or "application/atom+xml"


    You will get 404 Not Found if the folder does not exist

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,253 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans