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?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.Sign up to join this community
You can use this code:
byte contents = ...//your file's byte SPAttachmentCollection attachments = item.Attachments; attachments.Add("AttachmentName.txt", contents);