Click to Rate and Give Feedback

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (1)
SPPersistedObject Class (Microsoft.SharePoint.Administration)
Provides the methods for an object to automatically serialize its state, persist that state in a permanent store, retrieve it at a later time, and deserialize it back into an in-memory object.

Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
Public Class SPPersistedObject
    Inherits SPAutoSerializingObject
    Implements ICloneable
Visual Basic (Usage)
Dim instance As SPPersistedObject
C#
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
public class SPPersistedObject : SPAutoSerializingObject, ICloneable

The SPPersistedObject class provides a base class for all administration objects. It serializes all fields marked with the Persisted attribute to XML and writes the XML blob to the configuration database. The SPPersistedObject class contains code to serialize all its members that are base types, other persisted objects, and collections of persisted objects. Configuration data that is stored in persisted objects is automatically made available to every process on every server in the farm.

When you create a custom persisted object you must specify the default constructor for serialization.

To return an existing persisted object, use the GetObject method of the SPFarm class, or the GetChild method of the SPPersistedObject class.

The following example illustrates a custom class that inherits from the SPPersistedObject class where the Peristed attribute is used to specify fields for serialization.

Visual Basic
<GuidAttribute("3B60B328-F4D6-4902-BEC6-E904179FA246")>
Public Class MyObject
   Inherits SPPersistedObject
   <Persisted()>  _
   Private location As String

   <Persisted()>  _
   Private url As String

   Public Sub New()
   End Sub 'New
   
   'The default constructor must be specified for serialization.
   Public Sub New(name As String, parent As SPPersistedObject)
      MyBase.New(name, parent)
   End Sub 'New

   Public Overrides ReadOnly Property DisplayName() As String
      Get
         Return Me.url
      End Get
   End Property
   
   Public Property Url() As String
      Get
         Return Me.url
      End Get
      Set
         If Me.url = value Then
            Return
         End If

         Me.url = value
      End Set
   End Property

   Public Property Location() As String
      Get
         Return Me.location
      End Get
      Set
         Me.location = value
      End Set
   End Property
End Class 'MyObject
C#
[GuidAttribute("3B60B328-F4D6-4902-BEC6-E904179FA246")]
public class MyObject : SPPersistedObject
{
   [Persisted]
   private string location;

   [Persisted]
   private string url;

   public MyObject()
   {
   }
   /*The default constructor must be specified for serialization.*/
   public MyObject(string name, SPPersistedObject parent)
      : base(name, parent)
   {
      ;
   }

   public override string DisplayName
   {
      get
      {
         return this.url;
      }
   }

   public string Url
   {
      get { return this.url; }
      set 
      {
         if (this.url == value)
         {
            return;
          }

          this.url = value;
      }
   }

   public string Location
   {
      get { return this.location; }
      set { this.location = value; }
   }
}

After you create a MyObject persisted object as in the example, you can return it by using SPFarm.Local.GetObject(GUID).

System.Object
   Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
       Derived Classes
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker