I have a folder that contains attachments I need to attach to notes that already exist in CRM. Everything is working up to the point of attaching the file via C# console application. Here is my code:
try
{
string fullFilePath = noteGuid.attachmentLocation + "\\" + noteGuid.attachmentName;
byte[] convertedFile = Encoding.Unicode.GetBytes(fullFilePath);
ColumnSet attributes = new ColumnSet(new string[] { "annotationid", "filename", "documentbody", "isdocument", "mimetype" });
Entity annotation = new Entity("annotation");
annotation = orgService.Retrieve(annotation.LogicalName, noteGuid.RecordGuid, attributes);
if (annotation != null)
{
Console.WriteLine("Retrieved: " + annotation.Id);
annotation["annotationid"] = annotation.Id;
annotation["filename"] = noteGuid.attachmentName;
//annotation["documentbody"] = Convert.ToBase64String(new UnicodeEncoding().GetBytes(fullFilePath));
annotation["documentbody"] = Convert.ToBase64String(convertedFile);
annotation["mimetype"] = noteGuid.mimeType;
annotation["isdocument"] = 1;
orgService.Update(annotation);
Console.WriteLine("Note with GUID " + annotation.Id + " updated successfully!");
}
else
{
throw new Exception("Record Not Retrieved");
}
As you can see I did what the SDK and Microsoft article tell me to do, but I keep getting a cast error when the update step is hit.
*This post is locked for comments
I have the same question (0)