23 Temmuz 2013 Salı

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

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

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

Hiç yorum yok:

Yorum Gönder