SPBackupRestoreInformation.ReverseFileMapping 方法

获取包含指定的文件的备份文件的名称。

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

语法

声明
Public Function ReverseFileMapping ( _
    name As String _
) As String
用法
Dim instance As SPBackupRestoreInformation
Dim name As String
Dim returnValue As String

returnValue = instance.ReverseFileMapping(name)
public string ReverseFileMapping(
    string name
)

参数

  • name
    类型:System.String

    一个源文件,其中包含在备份文件的名称。

返回值

类型:System.String
表示名称的备份文件,其中包含已备份副本的nameString

备注

使用此方法来查找唯一的备份文件的名称已分配给由name参数标识的文件,由GenerateFileMapping方法。它通常称为**OnRestore()**的实现中。下面的示例,请参阅。

返回值的格式是hex.bak,其中hex是一个八位的十六进制数字。例如,"00000001.bak"或 0000000A.bak"。

name参数也是一个内部存储的键 / 值对中的键,并返回GenerateFileMapping的字符串为键的值。此键 / 值对是由GenerateFileMapping创建并存储在Location文件夹中的spbackup.xml文件。

备注

尽管GenerateFileMapping和ReverseFileMapping对相同的输入的响应返回完全相同的值,它们会做不同的事情。GenerateFileMapping创建唯一的文件名,并将写入spbackup.xml文件的映射的对的文件的名称。ReverseFileMapping 读取该文件中的映射。

示例

下面的示例演示了**OnRestore()**的实现中使用的ReverseFileMapping方法。有关完整的示例,请参见How to: Create a Content Class That Can Be Backed Up and Restored

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }

    // If the CriticalFiles object was deleted from the farm after it was
    // backed up, restore it to the configuration database.
    CriticalFiles cf = SPFarm.Local.GetChild<CriticalFiles>(this.Name);
    if (cf == null)
    {
        this.Update();
        args.Log(SPBackupRestoreLogSeverity.Verbose, this.Name + " added back to configuration database.");
    }

    Boolean successSignal = true;

    // TODO: The following loop restores files to the local server. If there are 
    //       multiple front end servers, your code must iterate through all of 
    //       SPFarm.Local.Servers and restore the same files to every server whose
    //       Role property is SPServerRole.WebFrontEnd

    foreach (String path in FrontEndFilePaths)
    {
        FileInfo backupCopy = new FileInfo(path);
        String mappedFileName = args.ReverseFileMapping(backupCopy.Name);
        FileInfo file = new FileInfo(args.Location + @"\" + mappedFileName);

        try
        {
            file.CopyTo(path, true);
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " + backupCopy.Name);
        }
        catch (Exception e)
        {
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name + " not restored: " + e.Message);
            successSignal = false;
        }
    }

    args.CurrentProgress = 50;
    return successSignal;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If

    ' If the CriticalFiles object was deleted from the farm after it was
    ' backed up, restore it to the configuration database.
    Dim cf As CriticalFiles = SPFarm.Local.GetChild(Of CriticalFiles)(Me.Name)
    If cf Is Nothing Then
        Me.Update()
        args.Log(SPBackupRestoreLogSeverity.Verbose, Me.Name & " added back to configuration database.")
    End If

    Dim successSignal As Boolean = True

    ' TODO: The following loop restores files to the local server. If there are 
    '       multiple front end servers, your code must iterate through all of 
    '       SPFarm.Local.Servers and restore the same files to every server whose
    '       Role property is SPServerRole.WebFrontEnd

    For Each path As String In FrontEndFilePaths
        Dim backupCopy As New FileInfo(path)
        Dim mappedFileName As String = args.ReverseFileMapping(backupCopy.Name)
        Dim file As New FileInfo(args.Location & "\" & mappedFileName)

        Try
            file.CopyTo(path, True)
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " & backupCopy.Name)
        Catch e As Exception
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name & " not restored: " & e.Message)
            successSignal = False
        End Try
    Next path

    args.CurrentProgress = 50
    Return successSignal
End Function

另请参阅

引用

SPBackupRestoreInformation 类

SPBackupRestoreInformation 成员

Microsoft.SharePoint.Administration.Backup 命名空间

GenerateFileMapping