Cette page vous a-t-elle été utile ?
Votre avis sur ce contenu est important. N'hésitez pas à nous faire part de vos commentaires.
Vous avez d'autres commentaires ?
1500 caractères restants
Exporter (0) Imprimer
Développer tout

SPListItemCollection, classe (Microsoft.SharePoint)

Windows SharePoint Services 3
Represents a collection of SPListItem objects.

Espace de noms : Microsoft.SharePoint
Assembly : Microsoft.SharePoint (dans microsoft.sharepoint.dll)

[DefaultMemberAttribute("Item")] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public class SPListItemCollection : SPBaseCollection

To return the collection of items for a list or document library, use the Items property or one of the GetItems methods of the SPList class, or use the Items property or GetItemsInFolder method of the SPDocumentLibrary class. To create an item, use one of the Add methods.

Use an indexer to return a single list item from the collection. For example, assuming the collection is assigned to a variable named collListItems, use collListItems[index] in C#, or collListItems(index) in Visual Basic 2005, where index is either the index number of the item in the collection or the display name of a list field.

Always use a Get* method on a higher-level SharePoint object to return specific items or files. If you use one of these methods, you are not required to enumerate all the items in the list or library. For example, instead of using the SPListItemCollection object, use the GetFile method of the SPWeb class to return a specific file from a library in a Web site, or use the GetItems method of the SPList class, and pass an SPQuery object to return specific items from a list.

The following code example uses the GetView method to return specific items from a source list in one site and then add these items to a destination list in another site.

SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsiteDest = oSiteCollection.AllWebs["Destination_Site"];
SPWeb oWebsiteSrc = oSiteCollection.AllWebs["Source_Site"];
SPList oList = oWebsiteSrc.Lists["Source_List"];
SPView oView = oList.Views["Source_View_Name"];

SPListItemCollection collListItemsSrc = oList.GetItems(oView);
SPListItemCollection collListItemsDest =
oWebsiteDest.Lists["Destination_List"].Items;

foreach (SPListItem oListItemSrc in collListItemsSrc)
{
    SPListItem oListItemDest = collListItemsDest.Add();

    oListItemDest["destField1_Name"] = oListItemSrc["srcField1_Name"];
    oListItemDest["destField2_Name"] = oListItemSrc["srcField2_Name"];
    oListItemDest["destField3_Name"] = oListItemSrc["srcField2_Name"];

    oListItemDest.Update();
}
oWebsiteDest.Dispose();
oWebsiteSrc.Dispose();
RemarqueRemarque :

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.

Les membres statiques publics de ce type (Shared en Visual Basic) sont sécurisés au niveau des threads. Il n'est pas garanti que les membres d'instance soient sécurisés au niveau des threads.
Microsoft réalise une enquête en ligne pour recueillir votre opinion sur le site Web de MSDN. Si vous choisissez d’y participer, cette enquête en ligne vous sera présentée lorsque vous quitterez le site Web de MSDN.

Si vous souhaitez y participer,
Afficher:
© 2015 Microsoft