Sunday 19 June 2011

Deleting an Attachment from SPList

Use below method to delete attachment of specific list item.

public void DeleteAttachment(int id,string fileName)
{
using (SPSite site = new SPSite("http://SiteCollectionURL"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyListName"];
SPListItem delItem = list.GetItemById(id);
SPAttachmentCollection files = delItem.Attachments;
files.Delete(fileName);
delItem.Update();
}
}
}

No comments:

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...