使用 Web 服务 Microsoft Dynamics CRM 添加文档共享点

Add document sharepoint using web service Microsoft Dynamics CRM

我的 Microsoft Dynamics CRM 中有一个帐户实体,我在 Sharepoint 中的每个帐户都有 文件夹,其中包含该帐户的文档我想使用 Web 服务 CRM IOrganizationService 在 c# 上创建应用程序以在 SharePoint 中添加文档。
有可能吗?
请任何链接来做到这一点。
我需要帮忙。
提前致谢

从您的问题可以理解,您已在 CRM Document Management System 中设置 SharePoint。您必须在 Document Management Settings 中启用 Document Location for Accounts。现在你要Create/Upload个文件到Sharepoint Library个。您可以使用 Sharepoint: Client Side Object Model(CSOM) 来做到这一点。我有一段代码可以在 sharepoint 中创建文档:

//Main Section Code
string sharePointUrl = GetDefaultSPSiteUrlFromCRMSiteCollectionEntity();
SharePointMethods sharePointMethods = new SharePointMethods(sharePointUrl, spUsername, spPassword, spDomain);

ClientContext context = sharePointMethods._clientContext;
Web web = sharePointMethods._clientContext.Web;
FileCreationInformation newFile = new FileCreationInformation();
  newFile.Content = System.IO.File.ReadAllBytes(newTempCRFDocumentFile);
  newFile.Url = sharePointFolder.ServerRelativeUrl+ CRFfileGeneratedName;
  newFile.Overwrite = true;
  List docs = web.Lists.GetByTitle("Account");
  Microsoft.SharePoint.Client.File uploadFile = sharePointFolder.Files.Add(newFile);
  context.ExecuteQuery();

辅助函数:

internal string GetDefaultSPSiteUrlFromCRMSiteCollectionEntity()
    {
        try
        {
            ConditionExpression c = new ConditionExpression("isdefault", ConditionOperator.Equal, true);
            FilterExpression f = new FilterExpression(LogicalOperator.And);
            f.Conditions.Add(c);

            QueryExpression q = new QueryExpression("sharepointsite");
            q.Criteria = f;
            q.ColumnSet = new ColumnSet("sharepointsiteid", "name", "absoluteurl", "relativeurl", "isdefault", "parentsite");

            EntityCollection crmSites = GRID.CRM.Common.Common.RetrieveMultiple(q);
            if (crmSites.Entities.Count > 0)
            {
                Entity defaultSharePointSite = crmSites.Entities[0];
                if (defaultSharePointSite.Attributes.Contains("parentsite") && defaultSharePointSite.Attributes.Contains("relativeurl"))
                {
                    Entity parentSiteOfDefaultSite = GRID.CRM.Common.Common.RetrieveSingle("sharepointsite", ((EntityReference)defaultSharePointSite["parentsite"]).Id);
                    return (string)parentSiteOfDefaultSite["absoluteurl"] + "/" + defaultSharePointSite.GetAttributeValue<string>("relativeurl");
                }
                else
                {
                    return defaultSharePointSite.GetAttributeValue<string>("absoluteurl");
                }
            }
            // no SharePoint Sites defined in CRM
            throw new Exception("CRM does not have any default SharePoint Sites");
        }
        catch (Exception ex)
        {
            throw new Exception("CrmMethods -> GetDefaultSPSite (" + ex.Message + ")");
        }
    }


internal class SharePointMethods
{
    string _siteUrl;
    public ClientContext _clientContext;
    internal SharePointMethods(string spSiteUrl, string spUsername, string spPassword, string spDomain)
    {
        try
        {
            _siteUrl = spSiteUrl;
            _clientContext = new ClientContext(_siteUrl);

            _clientContext.Credentials = new System.Net.NetworkCredential
                (spUsername, spPassword, spDomain);
        }
        catch (Exception ex)
        {
            throw new Exception("SharePointMethods.Constructor --> [" + ex.Message + "]");
        }
    }
}