我的 Microsoft Dynamics CRM 中有一个帐户实体以及我在Sharepoint中文件夹的每个帐户,其中包含我要创建应用的帐户的文档在c#上使用 Web Services CRM IOrganizationService 在SharePoint中添加文档。
它可能吗?
请做任何链接。
我需要帮忙。
提前谢谢你
答案 0 :(得分:1)
您可以理解,您已在CRM SharePoint
中设置Document Management System
。您必须在Document Location for Accounts
中启用Document Management Settings
。现在,您希望将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 + "]");
}
}
}