CRM 2011 - Not Varlığına Word Dosyası Ekleme (Attach Word Document to Annotation)

public static void AttachWordDocToNote(EntityReference account, IOrganizationService service)
        {
            // Open a file and read the contents into a byte array
            FileStream stream = File.OpenRead(@"C:\Lakshman\TDD.docx");
            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\ms-word";
            note.NoteText = "Note Added with Document attached.";

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

Hiç yorum yok:

Yorum Gönder