繁体   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