SPWeb.GetListItemFields-Methode
Ruft ab, das Listenelement, das der angegebenen serverrelative URL, Zurückgeben von Daten für nur die angegebenen Felder zugeordnet ist.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Public Function GetListItemFields ( _
strUrl As String, _
ParamArray fields As String() _
) As SPListItem
'Usage
Dim instance As SPWeb
Dim strUrl As String
Dim fields As String()
Dim returnValue As SPListItem
returnValue = instance.GetListItemFields(strUrl, _
fields)
public SPListItem GetListItemFields(
string strUrl,
params string[] fields
)
Parameter
strUrl
Typ: System.StringDie serverrelative URL, z. B. "/sites/MySite/Shared Documents/MyDocument.docx".
fields
Typ: []Die Namen der Felder für die Werte im Listenelement zurückgegeben werden.
Rückgabewert
Typ: Microsoft.SharePoint.SPListItem
Das Listenelement.
Ausnahmen
Ausnahme | Bedingung |
---|---|
ArgumentNullException | fields oder strUrl ist Null . |
Hinweise
Wenn fields ein leeres Array ist, gibt diese Methode keinen Wert für die Felder für das Listenelement zurück.
Diese Methode wird nur die Werte für den angegebenen Feldern im Listenelement. Wenn Sie ein Listenelement basierend auf einer Liste-Element-ID erhalten möchten, verwenden Sie die GetItemByIdSelectedFields(Int32, []) -Methode.
Beispiele
Im folgende Beispiel wird eine Konsolenanwendung, die ein Listenelement abruft, indem Sie eine URL und ein Array von Feldnamen angeben. Nachdem das Element abgerufen wird, wird die Anwendung die Feldwerte in der Konsole gedruckt.
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using site As SPSite = New SPSite("https://localhost")
Using web As SPWeb = site.OpenWeb()
' Build a server-relative Url for a list item.
Dim itemUrl As String = web.RootFolder.ServerRelativeUrl
itemUrl += "_catalogs/masterpage/default.master"
' Make a list of fields to fetch.
Dim itemFields() As String = {"ContentTypeId", _
"ContentType", _
"HTML_x0020_File_x0020_Type", _
"EncodedAbsUrl", _
"FileLeafRef", _
"UniqueId", _
"FileSizeDisplay"}
' Get the list item.
Dim item As SPListItem = web.GetListItemFields(itemUrl, itemFields)
' Print the values to the console.
Dim fieldName As String
For Each fieldName In itemFields
Console.WriteLine("{0} = {1}", fieldName, item(fieldName))
Next
End Using
End Using
Console.ReadLine()
End Sub
End Module
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
// Build a server-relative Url for a list item.
string itemUrl = web.RootFolder.ServerRelativeUrl;
itemUrl += "_catalogs/masterpage/default.master";
// Make a list of fields to fetch.
string[] itemFields =
{
"ContentTypeId",
"ContentType",
"HTML_x0020_File_x0020_Type",
"EncodedAbsUrl",
"FileLeafRef",
"UniqueId",
"FileSizeDisplay"
};
// Get the list item.
SPListItem item = web.GetListItemFields(itemUrl, itemFields);
// Print the values to the console.
foreach (string fieldName in itemFields)
Console.WriteLine("{0} = {1}", fieldName, item[fieldName]);
}
}
Console.ReadLine();
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Text
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using site As New SPSite("https://localhost")
Using web As SPWeb = site.OpenWeb()
If web.IsMultilingual Then
Dim sb As New StringBuilder()
Dim sep As String = ", "
Dim cultures As IEnumerable(Of CultureInfo) = web.SupportedUICultures
For Each culture As CultureInfo In cultures
sb.Append(culture.Name)
sb.Append(sep)
Next
Dim str As String = sb.ToString().Trim(sep.ToCharArray())
Console.WriteLine("Supported cultures: {0}", str)
End If
Console.WriteLine("Default culture: {0}", web.UICulture.Name)
End Using
End Using
Console.WriteLine(vbCrLf + "Press ENTER to continue....")
Console.Read()
End Sub
End Module