SPField class
代表SharePoint Foundation網站上的清單中的欄位。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPField
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Class SPField
'用途
Dim instance As SPField
public class SPField
備註
使用SPList類別或SPListItem類別的Fields屬性可傳回SPFieldCollection物件代表的欄位清單或清單項目集合。若要從這個集合中傳回單一欄位使用索引器。例如,若集合已指派給變數collFields,使用以 C# collFields[index]或collFields(index)Microsoft Visual Basic,在其中index是集合中欄位的索引編號,或是欄位的顯示名稱。
如果您將SPField類別和其繼承類別的屬性,您必須先呼叫以使變更生效的資料庫中的Update方法。
Examples
下列範例會為主控台應用程式,取得宣告清單中的到期日] 欄位的參照,並將預設的到期日設定為一週之後建立的項目。
using System;
using Microsoft.SharePoint;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists.TryGetList("Announcements");
if (list != null)
{
SPField fld = list.Fields[SPBuiltInFieldId.Expires];
fld.DefaultFormula = "=TODAY()+7";
fld.Update();
}
}
}
Console.Write("\nPress ENTER to continue....");
Console.Read();
}
}
}
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using site As New SPSite("https://localhost")
Using web As SPWeb = site.RootWeb
Dim list As SPList = web.Lists.TryGetList("Announcements")
If list IsNot Nothing Then
Dim fld As SPField = list.Fields(SPBuiltInFieldId.Expires)
fld.DefaultFormula = "=TODAY()+7"
fld.Update()
End If
End Using
End Using
Console.Write(vbCrLf & "Press ENTER to continue....")
Console.Read()
End Sub
End Module
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
請參閱
參照
Microsoft.SharePoint namespace
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPField
Microsoft.SharePoint.SPFieldAttachments
Microsoft.SharePoint.SPFieldBoolean
Microsoft.SharePoint.SPFieldCalculated
Microsoft.SharePoint.SPFieldComputed
Microsoft.SharePoint.SPFieldCrossProjectLink
Microsoft.SharePoint.SPFieldDateTime
Microsoft.SharePoint.SPFieldFile
Microsoft.SharePoint.SPFieldGeolocation
Microsoft.SharePoint.SPFieldGuid
Microsoft.SharePoint.SPFieldLookup
Microsoft.SharePoint.SPFieldMultiChoice
Microsoft.SharePoint.SPFieldMultiColumn
Microsoft.SharePoint.SPFieldMultiLineText
Microsoft.SharePoint.SPFieldNumber
Microsoft.SharePoint.SPFieldPageSeparator
Microsoft.SharePoint.SPFieldRecurrence
Microsoft.SharePoint.SPFieldText
Microsoft.SharePoint.SPFieldUrl