IBackupRestore.OnBackup 方法
创建并存储的内容的组件的备份副本。
命名空间: Microsoft.SharePoint.Administration.Backup
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Function OnBackup ( _
sender As Object, _
args As SPBackupInformation _
) As Boolean
用法
Dim instance As IBackupRestore
Dim sender As Object
Dim args As SPBackupInformation
Dim returnValue As Boolean
returnValue = instance.OnBackup(sender, _
args)
bool OnBackup(
Object sender,
SPBackupInformation args
)
参数
sender
类型:System.Object启动备份操作的对象。
args
类型:Microsoft.SharePoint.Administration.Backup.SPBackupInformationSPBackupInformation对象,该对象包含有关该操作的数据。
返回值
类型:System.Boolean
true如果成功 ;否则为false。
备注
如果您的内容类不有它可能具有的任何IBackupRestore子对象之外的任何内容,您的实现应只需将**CurrentProgess()**设置为至少 50%并返回true ,如下面的示例所示。请不要不调用任何IBackupRestore子对象的OnBackup方法。
public Boolean OnBackup(Object sender, SPBackupInformation args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
args.CurrentProgress = 50;
return true;
}
Public Function OnBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
If args Is Nothing Then
Throw New ArgumentNullException("args")
End If
args.CurrentProgress = 50
Return True
End Function
如果您类does之外可能有任何IBackupRestore子对象的内容,您的实现必须将这些内容复制到args。Location。如果由于某种原因失败的内容的副本,则返回false。
下面的示例显示**OnBackup()**的实体实现的总体结构:
public Boolean OnBackup(Object sender, SPBackupInformation args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
args.CurrentProgress = 50;
Boolean successSignal = true;
// TODO: Implement copying your content to args.Location
// If the copy fails, set successSignal to false.
return successSignal;
}
Public Function OnBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
If args Is Nothing Then
Throw New ArgumentNullException("args")
End If
args.CurrentProgress = 50
Dim successSignal As Boolean = True
' TODO: Implement copying your content to args.Location
' If the copy fails, set successSignal to false.
Return successSignal
End Function
如果 Windows 服务或应用程序,需要将停止或暂停在备份过程中,就可以在OnBackup(Object, SPBackupInformation)的开头。(在重新启动服务或应用程序OnBackupComplete。)即使它不备份 ; 不做OnPrepareBackup后, 一种方法称为对于每个组件,请在此工作但仅用于进行备份的组件称为OnBackupComplete ,准备备份阶段以便在中停止的服务或应用程序不能保证会获得重新启动。
如果OnPrepareBackup返回 false,则不会运行的OnBackup方法。如果OnBackup返回 false,则不会运行的OnBackupComplete方法。
示例
下面的示例演示将文件复制到备份位置的OnBackup的实现。FrontEndFilePaths是一个私有字段。它是包含要备份的文件的路径的字符串的集合。
public Boolean OnBackup(Object sender, SPBackupInformation args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
Boolean successSignal = true;
foreach (String path in FrontEndFilePaths)
{
FileInfo file = new FileInfo(path);
try
{
file.CopyTo(args.Location + @"\" + file.Name, true);
args.Log(SPBackupRestoreLogSeverity.Verbose, "Backed up " + file.Name);
}
catch (Exception e)
{
args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name + " not backed up: " + e.Message);
successSignal = false;
}
}
args.CurrentProgress = 50;
return successSignal;
}
Public Function OnBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
If args Is Nothing Then
Throw New ArgumentNullException("args")
End If
Dim successSignal As Boolean = True
For Each path As String In FrontEndFilePaths
Dim file As New FileInfo(path)
Try
file.CopyTo(args.Location & "\" & file.Name, True)
args.Log(SPBackupRestoreLogSeverity.Verbose, "Backed up " & file.Name)
Catch e As Exception
args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name & " not backed up: " & e.Message)
successSignal = False
End Try
Next path
args.CurrentProgress = 50
Return successSignal
End Function