我们有一个网站,客户写她的事件与附件。我可以获取事件并将其保存到Crm 2015系统中。Hovewer,我想保存的附件,如图片等。
我从xml中获取事件并逐一读取,然后将其保存到Crm 2015系统中:
foreach (XElement xmlIncident in xmlIncidents)
{
}在这个foreach中,我可以获得附着值:
var attachments = xmlIncident.Elements("attachments"); //get the collection of attachments.例如,在c#代码中,ın可能示例事件i有4个jpg的照片,其中一个似乎是这样的:
https://docs.sikayetvar.com/complaint/1054/10543034/gbhjk-1528636381_160x160.jpg https://docs.sikayetvar.com/complaint/1054/10543034/gbhjk-1528636381.jpg照片
我的问题是,如何使用c#从xml数据中获取附件并将其保存到CRM2015事件表中

发布于 2018-06-13 22:00:05
我想直接更新CRM数据库不是一个好主意,因为CRM SDK中有很多可用的东西。
要执行的步骤:
Annotation类型的实体,其中objectid =记录GUID 看看下面的代码,它应该可以为你工作
Guid AttachToIncident(string filePath, Guid recordGuid){
Func<string,string> imageToBase64 = (fpath) => {
using (Image image = Image.FromFile(fpath))
{
using (MemoryStream memStrm = new MemoryStream())
{
image.Save(memStrm, image.RawFormat);
byte[] imageBytes = memStrm.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
};
string fileName = Path.GetFileName(filePath);
Guid attachmentId = Guid.Empty;
Entity newAnnotation = new Entity("annotation");
newAnnotation["subject"] = "external attachment";
newAnnotation["filename"] = filename;
newAnnotation["mimetype"] = @"image/jpeg";
newAnnotation["documentbody"] = imageToBase64(filePath);
newAnnotation["objectid"] = new EntityReference("incident", recordGuid);
//you must be knowing what this service is ;)
attachmentId = orgService.Create(newAnnotation);
return attachmentId;
}https://stackoverflow.com/questions/50832919
复制相似问题