0

How to attach file in specific Custom list item in SharePoint online using Client Object model?

Any help is appreciated! Thanks!

1
using (ClientContext context = new ClientContext("http://SharepointURL/"))
{
    try
    {


        Web web = context.Web;

        FileCreationInformation newFile = new FileCreationInformation();
        newFile.Content = System.IO.File.ReadAllBytes(@"C:\test.txt");
        newFile.Url = "test.txt";

        List docs = web.Lists.GetByTitle("CustomList");
    ListItem item = docs.GetItemById(ID);

    var attInfo = new AttachmentCreationInformation();
    attInfo.FileName = mFile.Name;
    attInfo.ContentStream = new MemoryStream(System.IO.File.ReadAllBytes("streamFile"));

    Attachment att = item.AttachmentFiles.Add(attInfo); //Add to File

    context.Load(att);
    context.ExecuteQuery();
    Console.WriteLine("done");


    }
    catch (Exception ex)
    {
        throw ex;
    }
}

Hope this code helps you to attach file to list item.

  • Using Jsom upload document in sharepoint online – Mavani Apr 22 '16 at 12:38
  • In document library or in SharePoint online list item? – Hardik Apr 22 '16 at 12:39
  • Upload Document in Custom list sharepoint online listitem – Mavani Apr 22 '16 at 12:40
  • it is too much confusing. Please elaborate it. – Hardik Apr 22 '16 at 12:42
  • If you need JSOM code to upload attachment to list item than please follow this..sharepoint.stackexchange.com/questions/136577/… – Hardik Apr 22 '16 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.