Wednesday, January 16, 2019

How to attach files to list item using Client Object Model?

List list = web.Lists.GetByTitle("listtitle");
ListItem item = list.GetItemById(1);
var attachment = new AttachmentCreationInformation();
attachment.FileName = "fileName";
attachment.ContentStream = new MemoryStream(System.IO.File.ReadAllBytes("streamFile"));
Attachment att = item.AttachmentFiles.Add(attachment);                                        
context.Load(att);                                     
context.ExecuteQuery();       

No comments:

Post a Comment