删除网站中列表里的附件内容
private static void DelectAttachmentAll()
{
SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
try
{
SPList list = web.Lists[listname];
for (int i = 0; i < list.ItemCount; i++)
{
SPListItem item = list.Items[i];
if (item.Attachments != null)
{
SPAttachmentCollection att = item.Attachments;
for (int j = 0; j < att.Count; j++)
{
try
{
att.Delete(att[j]);
}
catch (Exception ex)
{ }
}
item.Update();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
finally
{
web.Close();
web.Dispose();
site.Dispose();
}
}