The following code example iterates through the collection of attachments for each Announcements list of every subsite and uses the indexer to display the file name of each attachment.
The example assumes the existence of an .aspx page that contains a label control named Label1.
Dim siteCollection As SPSite = SPContext.Current.Site
Dim subSites As SPWebCollection = siteCollection.AllWebs
Dim site As SPWeb
For Each site In subSites
Dim list As SPList = site.Lists("Announcements")
Dim listItems As SPListItemCollection = list.Items
Dim listItem As SPListItem
For Each listItem In listItems
Dim attachments As SPAttachmentCollection =
listItem.Attachments
Dim i As Integer
For i = 0 To attachments.Count - 1
Label1.Text += attachments(i)
Next i
Next listItem
Next site
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
foreach (SPWeb oWebsite in collWebsites)
{
SPList oList = oWebsite.Lists["Announcements"];
SPListItemCollection collListItems = oList.Items;
foreach (SPListItem oListItem in collListItems)
{
SPAttachmentCollection collAttachments = oListItem.Attachments;
for (int i=0; i<collAttachments.Count; i++)
{
Label1.Text += collAttachments[i];
}
}
}