使用Web服务Microsoft Dynamics CRM添加文档共享点 [英] Add document sharepoint using web service Microsoft Dynamics CRM

查看:86
本文介绍了使用Web服务Microsoft Dynamics CRM添加文档共享点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Microsoft Dynamics CRM 中有一个帐户实体,并且我在Sharepoint中拥有文件夹的每个帐户都包含我要创建应用程序的该帐户的文档在c#上使用 Web Services CRM IOrganizationService 在SharePoint中添加文档。

可能吗?

请执行任何链接。

我需要帮助。

预先感谢

I have an account entity in my Microsoft Dynamics CRM and the every account I have folder in Sharepoint which contains documents of this account I want to create app on c# using Web Services CRM IOrganizationService to Add Documents in SharePoint.
it's possible ?
Please any links to do that.
I need to help.
thanks in advance

推荐答案

从您的问题中可以理解的是,您已经在CRM 文档管理系统中设置了 SharePoint 。您必须在文档管理设置中启用帐户的文档位置。现在,您要创建/上载文档到 Sharepoint库。您可以使用 Sharepoint:客户端对象模型(CSOM)来完成。我有一段代码可以在sharepoint中创建文档:

from your Question what is understood is that you have setup SharePoint in CRM Document Management System. You must have enabled Document Location for Accounts in the Document Management Settings. Now you want to Create/Upload documents to the Sharepoint Library. You can use Sharepoint: Client Side Object Model(CSOM) to do that. I have a piece of code that creates documents in 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 + "]");
        }
    }
}

这篇关于使用Web服务Microsoft Dynamics CRM添加文档共享点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆