SPAttachmentCollection.Item 属性

获取集合中指定索引处的附件的文件名。[C#]在 C# 中,此属性是SPAttachmentCollection类的索引器。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public ReadOnly Default Property Item ( _
    iIndex As Integer _
) As String
    Get
用法
Dim instance As SPAttachmentCollection
Dim iIndex As Integer
Dim value As String

value = instance(iIndex)
public string this[
    int iIndex
] { get; }

参数

  • iIndex
    类型:System.Int32

    32 位整数,用于指定附件的索引。

属性值

类型:System.String
一个字符串,包含的文件名称。

示例

下面的代码示例循环访问每个子网站的每个通知列表的附件的集合,并使用索引器以显示每个附件的文件名。

该示例假定存在的.aspx 页,其中包含一个名为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];
        }
    }
}

备注

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

另请参阅

引用

SPAttachmentCollection 类

SPAttachmentCollection 成员

Microsoft.SharePoint 命名空间