четверг, 18 апреля 2013 г.

Удалить все вложения элемента в корзину

SPWeb web = SPContext.Current.Web;

web.AllowUnsafeUpdates = true;

SPList list = web.GetList(SPUrlUtility.CombineUrl(web.Url, listUrl);

SPListItem item = list.GetItemById(1);

SPAttachmentCollection attachmentCollection = item.Attachments;
                   
List<String> attachmentsList = new List<string>();

for (int i = 0; i < attachmentCollection.Count; i++)
{
       attachmentsList.Add(attachmentCollection[i]);                       
}

for (int i = 0; i < attachmentList.Count; i++)
{
      item.Attachments.Recycle(attachmentList[i]);
}
 item.Update();