Access SharePoint list item attachements through code

The code to access the list item attachements is a really simple code.
The attachments of a list item are stored as a collection of files for each list item.
This collection can be access through the Attachments property of the SPListItem object.

An example code is shown below.

// get a reference to the attachments collection
SPAttachmentCollection attachments = listItem.Attachments;
// loop through each file in the collection
foreach(SPFile in attachments)
{
    // your logic
}

Comments

Post a Comment

Popular posts from this blog

Create web part pages with custom layouts in SharePoint 2010

Create a Custom Timer Job in SharePoint 2010

SharePoint list forms display HTML instead of rendering