共用方式為


SPBackupRestoreInformation.GenerateFileMapping method

會包含指定的來源檔案的備份檔案的唯一名稱。

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

Syntax

'宣告
Public Function GenerateFileMapping ( _
    name As String _
) As String
'用途
Dim instance As SPBackupRestoreInformation
Dim name As String
Dim returnValue As String

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

參數

傳回值

Type: System.String
String ,代表包含name複本已備份之備份檔案的名稱。

備註

備份作業包含多個具有相同名稱的檔案時,這個方法是價值。若要確保每個個別備份,而不是覆寫彼此,此方法可以用來產生每個唯一的名稱。通常會呼叫它的**OnBackup()**實作中。請參閱下面的範例。

傳回值的格式是hex.bak hex所在八個位數的十六進位數字 ;例如,"00000001.bak"或 0000000A.bak"。

name參數也會成為關鍵值組的儲存區中的索引鍵,並傳回GenerateFileMapping的字串會變成鍵的值。此組會儲存在spbackup.xml資料夾中的檔案Location

注意事項注意事項

雖然GenerateFileMapping和ReverseFileMapping傳回完全相同的值相同的輸入回應,請他們內部進行不同的事項。GenerateFileMapping會建立的唯一檔案名稱,並spbackup.xml檔中寫入檔案名稱的對應的組的名稱。ReverseFileMapping 讀取該檔案中的對應。

Examples

下列範例顯示使用中實作的**OnBackup()**GenerateFileMapping方法。如需完整的範例,請參閱 < How to: Create a Content Class That Can Be Backed Up and Restored

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
        {
            String mappedFileName = args.GenerateFileMapping(file.Name);
            file.CopyTo(args.Location + @"\" + mappedFileName, true);
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Backed up " + file.Name + " (in " + mappedFileName + ")");
        }
        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
            Dim mappedFileName As String = args.GenerateFileMapping(file.Name)
            file.CopyTo(args.Location & "\" & mappedFileName, True)
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Backed up " & file.Name & " (in " & mappedFileName & ")")
        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

請參閱

參照

SPBackupRestoreInformation class

SPBackupRestoreInformation members

Microsoft.SharePoint.Administration.Backup namespace

ReverseFileMapping