Hi is there a way to attach file in specific Custom list item?
Currently i tried to add files on the root folder using below code:
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("MyCustomList");
ListItem item = docs.GetItemById(1);
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Folders.GetByUrl("Attachments").Files.Add(newFile); //Save file on Attachment folder but not creating new attachment folder for ListItem
context.Load(uploadFile);
context.ExecuteQuery();
Console.WriteLine("done");
}
catch (Exception ex)
{
throw ex;
}
}
Any help is appreciated! Thanks!