SPList.GetItems-Methode (SPView)
Gibt eine Auflistung von Elementen aus der Liste basierend auf der angegebenen Ansicht zurück.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Public Function GetItems ( _
view As SPView _
) As SPListItemCollection
'Usage
Dim instance As SPList
Dim view As SPView
Dim returnValue As SPListItemCollection
returnValue = instance.GetItems(view)
public SPListItemCollection GetItems(
SPView view
)
Parameter
view
Typ: Microsoft.SharePoint.SPViewDie Ansicht, in der Liste von Elementen verwenden.
Rückgabewert
Typ: Microsoft.SharePoint.SPListItemCollection
Die Listenelemente, die durch die Sicht angegeben.
Ausnahmen
Ausnahme | Bedingung |
---|---|
ArgumentNullException | view ist Null ( Visual BasicNothing ). |
Beispiele
Im folgende Beispiel ist eine Konsolenanwendung, die die Ansicht "Meine Aufgaben" der Liste verwendet, um Elemente abzurufen. Nach dem Abrufen der Daten, druckt die Anwendung einen einfachen Bericht an die Konsole.
Imports System
Imports System.Collections.Specialized
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using site As SPSite = New SPSite("https://localhost")
Using web As SPWeb = site.OpenWeb()
' Get data from a list.
Dim listUrl As String = web.ServerRelativeUrl + "/lists/tasks"
Dim list As SPList = web.GetList(listUrl)
Dim view As SPView = list.Views("My Tasks")
Dim items As SPListItemCollection = list.GetItems(view)
' Get a collection of view field names.
Dim viewFields As StringCollection = view.ViewFields.ToStringCollection()
' Print data for each item in the view.
Dim item As SPListItem
For Each item In items
' Print the value of each view field.
Dim fieldName As String
For Each fieldName In viewFields
Console.WriteLine("{0} = {1}", fieldName, item(fieldName))
Next fieldName
Console.WriteLine()
Next item
End Using
End Using
Console.ReadLine()
End Sub
End Module
using System;
using System.Collections.Specialized;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
// Get data from a list.
string listUrl = web.ServerRelativeUrl + "/lists/tasks";
SPList list = web.GetList(listUrl);
SPView view = list.Views["My Tasks"];
SPListItemCollection items = list.GetItems(view);
// Get a collection of view field names.
StringCollection viewFields = view.ViewFields.ToStringCollection();
// Print data for each item in the view.
foreach (SPListItem item in items)
{
// Print the value of each view field.
foreach (string fieldName in viewFields)
{
Console.WriteLine("{0} = {1}", fieldName, item[fieldName]);
}
Console.WriteLine();
}
}
}
Console.ReadLine();
}
}
}
Siehe auch
Referenz
Microsoft.SharePoint-Namespace
GetItems(String, [])