簡體   English   中英

如何通過使用C#代碼在Microsoft Dynamics 365中附加注釋中的圖像(注)

[英]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提供媒體類型

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM