SPFieldLookup.GetDependentLookupInternalNames method
傳回所有依存於主要的查閱欄位的次要的查閱欄位的內部名稱。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Function GetDependentLookupInternalNames As List(Of String)
'用途
Dim instance As SPFieldLookup
Dim returnValue As List(Of String)
returnValue = instance.GetDependentLookupInternalNames()
public List<string> GetDependentLookupInternalNames()
傳回值
Type: System.Collections.Generic.List<String>
相依尋查的字串清單為內部名稱。如果沒有相關的查閱欄位,則會傳回清單中有零 ( Count屬性會傳回 0) 的項目。
備註
如果IsRelationship屬性會傳回true, SPFieldLookup物件代表清單關聯性中的主要資料行。如果IsDependentLookup屬性會傳回true, SPFieldLookup物件代表清單關聯性中的第二個資料行。
Examples
下列範例會列舉欄位的集合] 清單中,尋找表示主要的資料行清單關聯性中的欄位的主控台應用程式。應用程式找到每一個主要資料行,它會列出任何依存於它的第二個資料行。
using System;
using System.Collections.Generic;
using Microsoft.SharePoint;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://localhost"))
{
using (SPWeb site = siteCollection.OpenWeb())
{
SPList list = site.Lists["Addresses"];
foreach (SPField field in list.Fields)
{
SPFieldLookup lookupField = field as SPFieldLookup;
if (lookupField != null && lookupField.IsRelationship)
{
// Print the display name of the field.
Console.WriteLine("\nPrimary column: {0}", lookupField.Title);
// Get any dependent fields.
List<string> internalNames = lookupField.GetDependentLookupInternalNames();
// Convert internal names to display names.
string[] displayNames = new string[internalNames.Count];
if (internalNames.Count == 0)
{
displayNames[0] = "No secondary columns.";
}
else
{
for (int i = 0; i < internalNames.Count; i++)
displayNames[i] = list.Fields.GetFieldByInternalName(internalNames[i]).Title;
// Print the display names.
Console.Write("Secondary columns: ");
Console.WriteLine(string.Join(", ", displayNames));
}
}
}
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As New SPSite("https://localhost")
Using site As SPWeb = siteCollection.OpenWeb()
Dim list As SPList = site.Lists("Addresses")
For Each field As SPField In list.Fields
Dim lookupField As SPFieldLookup = TryCast(field, SPFieldLookup)
If lookupField IsNot Nothing AndAlso lookupField.IsRelationship Then
' Print the display name of the field.
Console.WriteLine(vbLf & "Primary column: {0}", lookupField.Title)
' Get any dependent fields.
Dim internalNames As List(Of String) = lookupField.GetDependentLookupInternalNames()
' Convert internal names to display names.
Dim displayNames As String() = New String(internalNames.Count) {}
If internalNames.Count = 0 Then
displayNames(0) = "No secondary columns."
Else
Dim i As Integer = 0
While i < internalNames.Count
displayNames(i) = list.Fields.GetFieldByInternalName(internalNames(i)).Title
i = i + 1
End While
' Print the display names.
Console.Write("Secondary columns: | ")
Console.WriteLine(String.Join(" | ", displayNames))
End If
End If
Next
End Using
End Using
Console.Write(vbLf & "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module