public static void AttachTextToNote(EntityReference account, IOrganizationService service)
{
// Open a file and read the contents into a byte array
FileStream stream = File.OpenRead(@"C:\Lakshman\sample.txt");
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 = @"text/plain";
note.NoteText = "Note Added with Text attached.";
// Set the File Name
note.FileName = "Sample.txt";
service.Create(note);
}
Hiç yorum yok:
Yorum Gönder