Thursday 23 July 2015

How to upload a file attachment to a new list item using Sharepoint Online remotely

var list = Context.Web.Lists.GetById(listId);
Context.Load(list);
Context.ExecuteQuery();

var item = list.AddItem(new ListItemCreationInformation());
item["Title"] = "New Item with attachment";
item.Update()
context.ExecuteQuery();

var attInfo           = new AttachmentCreationInformation();
attInfo.FileName      = "Attachment name";
attInfo.ContentStream = new MemoryStream(attachmentData);

var att = item.AttachmentFiles.Add(attInfo);
Context.Load(att);
Context.ExecuteQuery();

No comments:

Post a Comment