Search code examples
sharepoint-2010attachment

Extract attached files from a Sharepoint list


Is there a way to extract all the attached files in a SharePoint list?


Solution

  • You can loop through each list item, and get each attachment.

    List<SPAttachment> attachments = new List<SPAttachment>();
    SPList list = SPContext.Current.Web.Lists["My List"];
    
    foreach (SPListItem item in list.Items)
    {
        attachments.AddRange(item.Attachments.Cast<SPAttachment>());
    }