我有一个自定义实体(“ ABC”),在CRM 365中查找了另一个自定义实体(“ PQR”)。我想将文件从“ PQR”复制到“ ABC”。 “ PQR”和“ ABC”的文件存储位置存储在SharePoint中的不同文档库位置。
我正在尝试使用CRM 365中的自定义工作流将文件从SharePoint中的一个文档库(“ PQR”)复制到另一文档库(“ ABC”)。
这是我到目前为止所尝试的:我尝试使用以下代码从库“ PQR”中获取文件内容,但在“ GetFiles”方法中出现序列化错误。
Guid siteId = new Guid("XXXXXXXXXXXXXX");
string sharepointEntityName = "somesharepointentityname";
ColumnSet sharepointEntitycolumnset = new ColumnSet("relativeurl","name");
FilterExpression sharepointEntityfilter = new FilterExpression();
sharepointEntityfilter.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active"));
sharepointEntityfilter.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, template.Id));
var site = (SharePointSite)service.Retrieve(SharePointSite.EntityLogicalName, siteId, new ColumnSet("sharepointsiteid", "absoluteurl"));
var sharepointList = CrmHelper.FetchMultipleRecords(sharepointEntityName, sharepointEntityfilter, sharepointEntitycolumnset, service);
tracingService.Trace("get sharepointList.");
if (sharepointList == null)
return;
var privateService = serviceFactory.CreateOrganizationService(null);
var docLocation = new DocumentLocationHelper(privateService, spService);
foreach (var sharepoint in sharepointList)
{
tracingService.Trace("get lists."+ sharepointList.Count);
string templateLibraryName = "SomeTemplate";
string templateFolderName = sharepoint.Attributes["relativeurl"].ToString();
tracingService.Trace("relativeurl" + templateFolderName);
string name = sharepoint.Attributes["name"].ToString();
tracingService.Trace("Name," + name);
var templatefile = spConn.GetRelativeFileFolderName(spsiteurl, templateLibrary);
tracingService.Trace("templatefile" + templatefile);
var templateFiles = docLocation.GetFiles(site, templateLibraryName, templateFolderName);
}
public string GetFiles(SharePointSite site, string libraryName, string folderName)
{
_spService.FetchFiles(site.AbsoluteURL, libraryName, folderName);
return "someString";
}
public void FetchFiles(string siteUrl, string libraryName, string folderName)
{
if (siteUrl != _siteUrl)
{
_siteUrl = siteUrl;
Uri spSite = new Uri(siteUrl);
_spo = SpoAuthUtility.CreateSP(spSite, _username, WebUtility.HtmlEncode(_password), false);
}
string odataQuery = "_api/web/GetFolderByServerRelativeUrl";
string digest = _spo.GetRequestDigest();
Uri url = new Uri(String.Format("{0}/{1}('{2}')/Files", _spo.SiteUrl, odataQuery, libraryName + "/" + folderName));
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,
"GET",
null,
webRequest,
_spo
);
string response = Encoding.UTF8.GetString(result, 0, result.Length);
}
任何帮助/建议都会有很大帮助。谢谢。