如何在Microsoft Dynamics 365中使用C#代码在Annotation(Note)中附加图片

How to attach Image in Annotation(Note) in Microsoft Dynamics 365 By using C# code

if (note.FileName !=null)
    noteEntity.Attributes.Add("filename", (note.FileName));
if (note.DocumentBody != null)
    noteEntity.Attributes.Add("documentbody", Convert.ToBase64String(note.DocumentBody)); `

对于使用此代码,我将附加 .txt 和 .doc 文件,但我想在 Dynamics crm 中的注释上附加图像文件,所以我如何附加图像文件?

您可以像这样创建附件,所有文件格式的过程都是一样的。要将您的文件视为图像,您需要通过 mimetype.

提供 media type
void AttachDocument(ICrmService service, Guid entityId, String entityType, String path, String mimeType)
{
    String fileName = Path.GetFileName(path); //load the attachment file from disk

    annotation a = new annotation(); //we have to create an annotation

    a.objectid = new Lookup(entityType, entityId); //and attach to a record, e.g. contact
    a.objecttypecode = new EntityNameReference(entityType);

    a.subject = fileName;

    a.filename = fileName; //the annotation has fields which contain the attachment information
    a.mimetype = mimeType;
    a.documentbody = Convert.ToBase64String(File.ReadAllBytes(path)); //crm like us to store attachments as base64 strings

    service.Create(a);
}