Share via


SPContentType.Update-Methode (Boolean)

Aktualisiert die Inhaltstypdefinition, die in der Datenbank gespeichert ist und aktualisiert optional alle Inhaltstypen, die von diesem Inhaltstyp erben.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Sub Update ( _
    updateChildren As Boolean _
)
'Usage
Dim instance As SPContentType
Dim updateChildren As Boolean

instance.Update(updateChildren)
public void Update(
    bool updateChildren
)

Parameter

  • updateChildren
    Typ: System.Boolean

    true , drücken Sie die Änderungen an den Inhaltstyp nach unten zu Inhaltstypen, die von ihm erben; andernfalls false.

Ausnahmen

Ausnahme Bedingung
SPContentTypeSealedException

Die Sealed -Eigenschaft dieses Inhaltstyps oder ein untergeordnetes Element des Inhaltstyps hat den Wert true.

SPContentTypeReadOnlyException

Die ReadOnly -Eigenschaft dieses Inhaltstyps oder ein untergeordnetes Element des Inhaltstyps hat den Wert true.

Hinweise

Wie Sie Änderungen an einem Websiteinhaltstyp über das Objektmodell vornehmen, macht Code diese Änderungen tatsächlich in die speicherinterne Darstellung des Websiteinhaltstyps. Nur bei einem Aufruf die Update -Methode SharePoint Foundation diese Änderungen vornehmen dauerhafter, durch deren Aufnahme wieder in der Inhaltstypdefinition, die in der Standortdatenbank gespeichert ist.

Weitere Informationen finden Sie unter Updating Content Types.

Wenn Sie Änderungen an einem Websiteinhaltstyp vornehmen, Sie auswählen können, weitergegeben oder weitergeben, Änderungen an den übergeordneten Inhaltstyp seine untergeordneten, und führen Sie Inhaltstypen.

Weitere Informationen finden Sie unter Updating Child Content Types.

Beispiele

Das folgende Beispiel ist eine Konsolenanwendung, mit die eine Verknüpfung dar erstellt mithilfe einer vorhandenen Websitespalte zu einem Websiteinhaltstyp hinzugefügt, und aktualisiert anschließend den Inhaltstyp ohne die Änderung seine untergeordneten Inhaltstypen weiterzugeben.

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 ctName As String = "Contact" ' Content type to modify
                Dim fldName As String = "Birthday" ' Site field to link to

                ' Get the content type to modify.
                Dim ct As SPContentType = web.ContentTypes(ctName) ' Null if not found
                If ct Is Nothing Then
                    Console.WriteLine("{0} is not a site content type.", ctName)
                End If

                ' Get the field to link to.
                Dim fld As SPField = Nothing
                Try
                    fld = web.Fields.GetField(fldName) ' Throws exception if not found
                Catch ex As ArgumentException
                    Console.WriteLine("{0} is not a site column.")
                End Try

                ' Add a field link to the content type. 
                If Nothing IsNot fld AndAlso Nothing IsNot ct Then
                    Dim lnk As New SPFieldLink(fld)
                    If Nothing Is ct.FieldLinks(lnk.Id) Then ' Does it exist in collection?
                        'No, so add it.
                        ct.FieldLinks.Add(lnk)

                        ' Update the content type.
                        Try
                            ct.Update(False) ' Do not push down
                            Console.WriteLine("A link to {0} has been added to content type {1}.", fldName, ctName)
                        Catch ex As SPException
                            Console.Write("Update failed. ")
                            Console.WriteLine(ex.Message)
                        End Try
                    Else ' We have a duplicate link
                        Console.WriteLine("Content type {0} already has a link to {1}.", ctName, fldName)
                    End If
                End If
            Finally
                web.Dispose()
            End Try
            Finally
                site.Dispose()
            End Try
        Console.Write(vbCrLf + "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 ctName = "Contact";   // Content type to modify
                    string fldName = "Birthday"; // Site field to link to

                    // Get the content type to modify.
                    SPContentType ct = web.ContentTypes[ctName]; // Null if not found
                    if (ct == null)
                        Console.WriteLine("{0} is not a site content type.", ctName);

                    // Get the field to link to.
                    SPField fld = null;
                    try
                    {
                        fld = web.Fields.GetField(fldName); // Throws exception if not found
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("{0} is not a site column.");
                    }

                    // Add a field link to the content type.
                    if (null != fld  && null != ct)
                    {
                        SPFieldLink lnk = new SPFieldLink(fld);
                        if (null == ct.FieldLinks[lnk.Id]) // Does it exist in collection?
                        {
                            //No, so add it.
                            ct.FieldLinks.Add(lnk);

                            // Update the content type
                            try
                            {
                                ct.Update(false); // Do not push down
                                Console.WriteLine("A link to {0} has been added to content type {1}.", fldName, ctName);
                            }
                            catch (SPException ex)
                            {
                                Console.Write("Update failed. ");
                                Console.WriteLine(ex.Message);
                            }
                        }
                        else // We have a duplicate link.
                        {
                            Console.WriteLine("Content type {0} already has a link to {1}.", ctName, fldName);
                        }
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.ReadLine();
        }
    }
}

Siehe auch

Referenz

SPContentType Klasse

SPContentType-Member

Update-Überladung

Microsoft.SharePoint-Namespace

Weitere Ressourcen

Updating Content Types

Updating Child Content Types

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy