问题描述
我是CRM的新手.尝试创建带有附件的电子邮件.使电子邮件创建部分正常工作,但是在附加要从文件资源管理器附加的文件时遇到了困难.
I am a newbie to CRM. Trying to create an email with an attachment. Got the email creation part working but facing a hard time in attaching the file that I want to attach from the file explorer.
activitymimeattachment实体具有一个称为文件名"的属性,但它会附加具有给定名称的空文件,而不是来自文件资源管理器中的文件.尝试在filename属性中提供文件的完整路径,但仅附加具有给定名称的文件,而不附加来自资源管理器的文件.
The activitymimeattachment entity has an attribute called "filename" but that attaches an empty file with the given name rather than the file from file explorer. Tried giving the full path of the file in the filename attribute but that attach only the file with the given name, but not from the explorer.
这是我必须在电子邮件中附加文件的代码.
This is the code I have to attach a file to the email.
Entity attach = new Entity("activitymimeattachment");
attach["filename"] = "Stack.txt";
attach["mimetype"] = "text/plain";
attach["attachmentnumber"] = 1;
attach["objectid"] = new EntityReference("email", emailId);
attach["objecttypecode"] = "email";
service.Create(attach);
Stack.txt文件位于我的C:/users/name/Files/Stack.txt
Stack.txt file is in my C:/users/name/Files/Stack.txt
如何指定activitymimeattachment属性的文件路径?
How do I specify the file path to the activitymimeattachment attribute?
对该问题的任何回答都会很有帮助.
Any answer to the question would be much helpful.
谢谢.
推荐答案
您需要阅读文本并将base64编码为 body
属性:
You need to read in the text and base64 encode it to the body
attribute:
attach ["body"] = System.Convert.ToBase64String(新ASCIIEncoding().GetBytes(System.IO.File.ReadAllText(@"C:\ Temp \ alljobs.txt"))));
这篇关于如何在CRM中的Activitymimeattachment实体中添加文件路径和文件名属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!