How can I upload a file to a SharePoint list from code? I need to upload a file as an attachment to the list item through code.

I use an ASP: FileUpload for the search and selection of the file but how can I save that file in the list?

Thank You


You can use this code:

byte[] contents = ...//your file's byte[]
SPAttachmentCollection attachments = item.Attachments;
attachments.Add("AttachmentName.txt", contents);


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.