Partager via


SPDocumentLibrary.Items Property

Returns all files within the document library, including those in any subfolders.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

Public Overrides ReadOnly Property Items As SPListItemCollection
    Get

Dim instance As SPDocumentLibrary
Dim value As SPListItemCollection

value = instance.Items
public override SPListItemCollection Items { get; }

Property Value

Type: Microsoft.SharePoint.SPListItemCollection
An SPListItemCollection object that represents all files in the document library.

Remarks

In Microsoft Visual C#, this property is the indexer for the collection of files within the document library.

Use the GetItemsInFolder method to return items from specific folders within the document library.

Examples

The following code example displays the relative path based on the site and the file name for every file in the document library.

The example assumes the existence of an .aspx page that contains a label control.

Dim site As SPSite = SPControl.GetContextSite(Context)
Dim web As SPWeb = site.AllWebs("Site_Name")

Dim docLib As SPDocumentLibrary = CType(web.Lists("DocLib_Name"), SPDocumentLibrary)
Dim items As SPListItemCollection = docLib.Items
Dim item As SPListItem

For Each item In  items

    Label1.Text += SPEncode.HtmlEncode(item.File) & "<BR>"

Next item 
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"];

SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)oWebsite.Lists["DocLib_Name"];

SPListItemCollection collListItems = oDocumentLibrary.Items;

foreach (SPListItem oListItem in collListItems)
{
    Label1.Text += SPEncode.HtmlEncode(oListItem.File) + "<BR>";
}
oWebsite.Dispose();

Note

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 Best Practices: Using Disposable Windows SharePoint Services Objects.

See Also

Reference

SPDocumentLibrary Class

SPDocumentLibrary Members

Microsoft.SharePoint Namespace