Export (0) Print
Expand All

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)

void AddBackupObjects(
	SPBackupRestoreObject parent


Type: Microsoft.SharePoint.Administration.Backup.SPBackupRestoreObject

The backup object to which the IBackupRestore objects are added.

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 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. 

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;

Community Additions

© 2014 Microsoft