IBackupRestore.AddBackupObjects 方法

IBackupRestore对象和它的子IBackupRestore对象添加到指定的备份对象。

命名空间:  Microsoft.SharePoint.Administration.Backup
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Sub AddBackupObjects ( _
    parent As SPBackupRestoreObject _
)
用法
Dim instance As IBackupRestore
Dim parent As SPBackupRestoreObject

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

参数

备注

AddBackupObjects的实现需要完成以下操作:

  • 确保一个SPBackupRestoreObject对象,该对象表示自定义内容组件被创建并添加到树中的SPBackupRestoreObject对象将处理在备份或还原操作。

  • 请确保SPBackupRestoreObject对象为内容实现IBackupRestore的组件添加到树中的每个孩子。

  • 指定类型名称和可以使用 stsadm.exe,管理中心应用程序的用户界面或SharePoint Management Shell cmdlet 或一些其他备份恢复应用程序的用户界面组件的说明。

下面的示例显示了**AddBackupObjects()**方法的简单实现。您可能需要或想要添加到您的实现的其他事项包括:

  • 对**SetParameter()**方法调用的第二个参数,请考虑所调用的方法使用当前区域性信息返回的本地化的字符串。

  • 如果您的子对象有时应该可供选择的备份、 恢复或还原-与-a-新的名称,但其他时候不能 ;请考虑使用在子对象上迭代设置为每个孩子的CanSelectForBackupCanSelectForRestore,或CanRenameOnRestore属性。在以下示例中, childIBR是子类别的对象,和SupportedWebApp是该属性返回对SPWebApplication对象所支持的引用。由于管理 Web 应用程序不能选择用于备份或还原独立于其父,也不应支持的内容对象。

    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
    
  • 如果内容类的对象可以在树中的组件的备份或还原操作将处理 ; 有时是顶部组件 (而不是服务器场)但在其他时间的子的一些较高的 (非场) 自定义组件,那么AddBackupObjects方法必须检查以查看是否对象已添加到树中由父对象的AddBackupObjects调用。若要执行此操作,包装所有您的实现逻辑 (后检查父对象是否空引用(无 在 Visual Basic 中)) 在某一条件的结构,如下面的示例中所示。

    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
    

示例

以下是实现的**AddBackupObjects()**方法的一个示例。此示例假定您内容的类具有子IBackupRestore对象的ChildContentCollection 。如果您的类具有多个类型的子组件,可能会有不同的集合,每个类型和循环访问每个集合。

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

另请参阅

引用

IBackupRestore 接口

IBackupRestore 成员

Microsoft.SharePoint.Administration.Backup 命名空间