次の方法で共有


IBackupRestore.AddBackupObjects method

Adds the IBackupRestore object and its child IBackupRestore objects to the specified backup object.

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

Syntax

'Declaration
Sub AddBackupObjects ( _
    parent As SPBackupRestoreObject _
)
'Usage
Dim instance As IBackupRestore
Dim parent As SPBackupRestoreObject

instance.AddBackupObjects(parent)
void AddBackupObjects(
    SPBackupRestoreObject parent
)

Parameters

Remarks

An implementation of AddBackupObjects needs to accomplish the following things:

  • Ensure that a SPBackupRestoreObject object that represents your custom content component is created and added to the tree of SPBackupRestoreObject objects that will be processed by the backup or restore operation.

  • Ensure that a SPBackupRestoreObject object for each child content component that implements IBackupRestore is added to the tree.

  • Specify a type name and a description for the component that can be used by the UI of the Central Administration application, or stsadm.exe, or the UI of a SharePoint Management Shell cmdlet, or some other backup restore application.

The example below shows a simple implementation of the AddBackupObjects() method. Other things you may need or want to add to your implementation include the following:

  • For the second parameter of the calls to the SetParameter() method, consider calling a method that uses current culture information to return a localized string.

  • If your child objects should sometimes be selectable for backup, restore, or restore-with-a-new-name, but other times not be; consider using the iteration over the child objects to set the CanSelectForBackup, CanSelectForRestore, or CanRenameOnRestore properties for each child. In the following example, childIBR is an object of a child class and SupportedWebApp is a property that returns a reference to the SPWebApplication that is supported by the object. Since the Administration Web Application cannot be selected for backup or restore separately from its parent, neither should the supporting content object.

    if (childIBR.SupportedWebApp is SPAdministrationWebApplication)
    {
        childIBR.CanSelectForBackup == false;
        childIBR.CanSelectForRestore == false;
    }
    
    If TypeOf childIBR.SupportedWebApp Is SPAdministrationWebApplication Then
        childIBR.CanSelectForBackup = False
        childIBR.CanSelectForRestore = False
    End If
    
  • If an object of your content class can sometimes be the top component (other than the farm) in the tree of components that the backup or restore operation will process; but is at other times the child of some higher (non-farm) custom component, then the AddBackupObjects method must check to see whether the object was already added to the tree by a call to the AddBackupObjects of the parent object. To do this, wrap all of your implementation logic (after checking whether the parent is a null reference (Nothing in Visual Basic)) in a conditional structure such as shown in the following example.

    if (parent == null)
    {
        throw new ArgumentNullException("parent");
    }
    if (parent.FindObject(this.Id) == null)
    {
        // TODO: Insert here all of your implementation logic
        // after the check of the parent's validity. 
    }
    
    If parent Is Nothing Then
        Throw New ArgumentNullException("parent")
    End If
    If parent.FindObject(Me.Id) Is Nothing Then
        ' TODO: Insert here all of your implementation logic
        ' after the check of the parent's validity. 
    End If
    

Examples

The following is an example of an implementation of the AddBackupObjects() method. This example assumes that your content class has a ChildContentCollection of child IBackupRestore objects. If your class has more than one type of child component, you may have separate collections for each type and iterate through each collection.

public void AddBackupObjects(SPBackupRestoreObject parent)
{
    if (parent == null)
    {
        throw new ArgumentNullException("parent");
    }

    SPBackupRestoreObject self = parent.AddChild(this);
    self.Information.SetParameter(SPBackupRestoreObject.SPTypeName, this.GetType());
    self.Information.SetParameter(SPBackupRestoreObject.SPDescription, "Description of custom content component");

....foreach (ChildContent child in ChildContentCollection)
    {
        IBackupRestore childIBR = child as IBackupRestore;
        childIBR.AddBackupObjects(self);
    }
}
Public Sub AddBackupObjects(ByVal parent As SPBackupRestoreObject)
    If parent Is Nothing Then
        Throw New ArgumentNullException("parent")
    End If

    Dim self As SPBackupRestoreObject = parent.AddChild(Me)
    self.Information.SetParameter(SPBackupRestoreObject.SPTypeName, Me.GetType())
    self.Information.SetParameter(SPBackupRestoreObject.SPDescription, "Description of custom content component")

For Each child As ChildContent In ChildContentCollection
        Dim childIBR As IBackupRestore = TryCast(child, IBackupRestore)
        childIBR.AddBackupObjects(self)
Next child
End Sub

See also

Reference

IBackupRestore interface

IBackupRestore members

Microsoft.SharePoint.Administration.Backup namespace