Sunday, February 5, 2012

Programmtically list all attachements in a List

public void fnListAttachments(string site, string listName)
{
    StringBuilder strAttachNames= new StringBuilder();
    using (SPSite oSite = new SPSite(site))
    {
        using (SPWeb oWeb = oSite.OpenWeb())
        {
            SPList oList = oWeb.Lists[listName];

            SPListItemCollection oListItems = oList.Items;
            foreach (SPListItem item in oListItems)
            {
                SPAttachmentCollection attachmentscol= item.Attachments;

                if (attachmentscol.Count <= 0) return string.Empty;

                foreach (var attachment in attachmentscol)
                {
                    strAttachNames.Append(attachment.ToString());
                }
            }
        }
    }
    //return strAttachNames.ToString();
}

No comments:


A sales engineer is someone who promise you a bridge, even when there's no river.