Gets the file name of the attachment at the specified index in the collection. [C#] In C#, this property is the indexer for the
SPAttachmentCollection class.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public ReadOnly Default Property Item ( _
iIndex As Integer _
) As String
Dim instance As SPAttachmentCollection
Dim iIndex As Integer
Dim value As String
value = instance(iIndex)
public string this [
int iIndex
] { get; }
Parameters
- iIndex
A 32-bit integer that specifies the index of the attachment.
Property Value
A string that contains the file name.
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];
}
}
}