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.
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 file is in my C:/users/name/Files/Stack.txt
How do I specify the file path to the activitymimeattachment attribute?
Any answer to the question would be much helpful.
Thanks in advance.
You need to read in the text and base64 encode it to the body
attribute:
attach["body"] = System.Convert.ToBase64String(new ASCIIEncoding().GetBytes(System.IO.File.ReadAllText(@"C:\Temp\alljobs.txt")));