This documentation is archived and is not being maintained.

SPDocumentLibrary.Items Property

Windows SharePoint Services 3

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

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

public override SPListItemCollection Items { get; }

Property Value

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

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.

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.

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>";

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.