[英]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 ? 对于此代码使用,我将附加.txt和.doc文件,但我想在Dynamics crm中的“注释”上附加图像文件,因此如何附加图像文件?
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
. 要将文件视为图像,您需要通过
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.