简体   繁体   中英

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)); `

For This Code Using I will attach .txt and .doc file but I want to attach Image file on Note in Dynamics crm so How I attach image file ?

You can create an attachment like so, the process is the same for all file formats. To have your file treated as an image, you need to provide the media type via the mimetype .

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM