SPFieldLinkCollection.Item property (Guid)
從集合中取得指定的SPFieldLink物件藉由使用其識別碼 (ID)。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public ReadOnly Default Property Item ( _
id As Guid _
) As SPFieldLink
Get
'用途
Dim instance As SPFieldLinkCollection
Dim id As Guid
Dim value As SPFieldLink
value = instance(id)
public SPFieldLink this[
Guid id
] { get; }
參數
id
Type: System.Guid要擷取之SPFieldLink物件的 [ Id ] 屬性的值。
Property value
Type: Microsoft.SharePoint.SPFieldLink
SPFieldLink物件。
備註
如果找不到指定的物件,索引子會傳回 null。
Examples
下列範例會逐一查看的內容類型都可在網站層級中,尋找參考至特定網站的資料行的主控台應用程式。
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Dim site As SPSite = New SPSite("https://localhost")
Try
Dim web As SPWeb = site.OpenWeb()
Try
Dim fldName As String = "WorkPhone"
Try
Dim fld As SPField = web.Fields.GetField(fldName) 'Throws exception if field not found
For Each ct As SPContentType In web.AvailableContentTypes
Dim fldLnk As SPFieldLink = ct.FieldLinks(fld.Id)
If fldLnk IsNot Nothing Then
Console.WriteLine("Content type {0} links to the {1} field.", _
ct.Name, fldName)
End If
Next ct
Catch ex As ArgumentException
Console.WriteLine("ArgumentException thrown by {0}.", ex.TargetSite)
Console.WriteLine("Argument passed to GetField is '{0}'.", fldName)
End Try
Finally
web.Dispose()
End Try
Finally
site.Dispose()
End Try
Console.Write("Press ENTER to continue...")
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())
{
string fldName = "WorkPhone";
try
{
SPField fld = web.Fields.GetField(fldName); // Throws exception if field not found
foreach (SPContentType ct in web.AvailableContentTypes)
{
SPFieldLink fldLnk = ct.FieldLinks[fld.Id];
if (fldLnk != null)
{
Console.WriteLine("Content type {0} links to the {1} field.",
ct.Name, fldName);
}
}
}
catch (ArgumentException ex)
{
Console.WriteLine("ArgumentException thrown by {0}.", ex.TargetSite);
Console.WriteLine("Argument passed to GetField is '{0}'.", fldName);
}
}
}
Console.Write("Press ENTER to continue...");
Console.ReadLine();
}
}
}
請參閱
參照
Microsoft.SharePoint namespace