CRM 2011 - Not Varlığına PDF Dosyası Ekleme(Attach PDF To Annotation)

public static void AttachPDFToNote(EntityReference account, IOrganizationService service)
        {
            // Open a file and read the contents into a byte array
            FileStream stream = File.OpenRead(@"C:\Lakshman\TDD1.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);

            // Add the Note
            Annotation note = new Annotation();

            // Im going to add Note to Account entity
            note.ObjectId = account;
            note.Subject = "Note Added with attachment";

            // Set EncodedData to Document Body
            note.DocumentBody = encodedData;

            // Set the type of attachment
            note.MimeType = @"application\pdf";
            note.NoteText = "Note Added with pdf attached.";

            // Set the File Name
            note.FileName = "TDD1.pdf";
            service.Create(note);
        }

Hiç yorum yok:

Yorum Gönder