Creating PDF notes programmatically in CRM 2015
Hi Folks,
This post will help you in creating notes attachment into CRM programmatically.
// Open a file and read the contents into a byte array
FileStream stream = File.OpenRead(@"c:\testfile.pdf");
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);
stream.Close();
// Encode the data using base64.
string encodedData = System.Convert.ToBase64String(byteData);
// Instantiate an Annotation object.
// See the Entity Metadata topic in the SDK documentation to determine
// which attributes must be set for each entity.
Annotation createAnnotation = new Annotation()
{
Subject = "PDF Attachment",
FileName = "File Name",
DocumentBody = encodedData,
MimeType = @"application\pdf"
};
// Create the Annotation object.
_annotationId = _serviceProxy.Create(createAnnotation);
In the above code snippet you can change the MimeType based on the type of file that want to upload into CRM. For ex., application/msword for Microsoft Word, application/pdf for PDF etc.,
Hope this helps.
Thanks,
Vishnu