Freigeben über


SPBackupRestoreConsole.FindItems-Methode

Ruft die angegebenen SharePoint Foundation Komponenten aus der angegebenen Sicherungs- oder Wiederherstellungsvorgang ab.

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

Syntax

'Declaration
Public Shared Function FindItems ( _
    id As Guid, _
    item As String _
) As SPBackupRestoreObjectCollection
'Usage
Dim id As Guid
Dim item As String
Dim returnValue As SPBackupRestoreObjectCollection

returnValue = SPBackupRestoreConsole.FindItems(id, _
    item)
public static SPBackupRestoreObjectCollection FindItems(
    Guid id,
    string item
)

Parameter

  • item
    Typ: System.String

    Der Name der eine Komponente, die gesichert oder wiederhergestellt werden kann oder einen Teil des Namens, der mehrere Komponenten entspricht.

Rückgabewert

Typ: Microsoft.SharePoint.Administration.Backup.SPBackupRestoreObjectCollection
Eine SPBackupRestoreObjectCollection , die alle SPBackupRestoreObject darstellt, deren Namen itemverglichen.

Beispiele

Die folgende Abbildung zeigt der SPBackupRestoreObjectCollection -Klasse, dass einzelne Komponenten werden im oberen Bereich die Struktur von Komponenten, die verarbeitet werden durch eine Sicherung oder Wiederherstellung identifiziert, die in einer Methode, mit die sichergestellt wird, dass ein Benutzer der Namen der Komponente eindeutig übermittelten verwendet wird. Das vollständige Beispiel und eine ausführliche Erläuterung des es finden Sie unter How to: Programmatically Back Up Content.

private static SPBackupRestoreObject EnsureUniqueValidComponentName(SPBackupRestoreSettings settings, ref Guid operationGUID)
{
    SPBackupRestoreObjectCollection list = SPBackupRestoreConsole.FindItems(operationGUID, settings.IndividualItem);
    SPBackupRestoreObject component = null;

    if (list.Count <= 0)
    {
        Console.WriteLine("There is no component with that name. Run again with a new name.");
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
    else if (list.Count > 1)  // The component name specified is ambiguous. Prompt user to be more specific.
    {
        Console.WriteLine("More than one component matches the name you entered.");
        Console.WriteLine("Run again with one of the following:");
        for (int i = 0; i < list.Count; i++)
        {
            Console.WriteLine("\t{0}", list[i].ToString());
        }
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
    else
    {
        component = list[0];
    }

    return component;

}// end EnsureUniqueValidComponentName
Private Shared Function EnsureUniqueValidComponentName(ByVal settings As SPBackupRestoreSettings, ByRef operationGUID As Guid) As SPBackupRestoreObject
    Dim list As SPBackupRestoreObjectCollection = SPBackupRestoreConsole.FindItems(operationGUID, settings.IndividualItem)
    Dim component As SPBackupRestoreObject = Nothing

    If list.Count <= 0 Then
        Console.WriteLine("There is no component with that name. Run again with a new name.")
        Console.WriteLine("Press Enter to continue.")
        Console.ReadLine()
    ElseIf list.Count > 1 Then ' The component name specified is ambiguous. Prompt user to be more specific.
        Console.WriteLine("More than one component matches the name you entered.")
        Console.WriteLine("Run again with one of the following:")
        For i As Integer = 0 To list.Count - 1
            Console.WriteLine(vbTab & "{0}", list(i).ToString())
        Next i
        Console.WriteLine("Press Enter to continue.")
        Console.ReadLine()
    Else
        component = list(0)
    End If

    Return component

End Function ' end EnsureUniqueValidComponentName

Das folgende Beispiel zeigt, wie Sie diese Methode in einer Konsolenanwendung, die alle Komponenten in der Farm in einer Strukturansicht anzeigt.

static void Main(string[] args)
{
    SPBackupSettings settings = (SPBackupSettings)SPBackupRestoreSettings.GetBackupSettings(@"\\server\Backups", "full");
    Guid backup = SPBackupRestoreConsole.CreateBackupRestore(settings);

    SPBackupRestoreObjectCollection list = SPBackupRestoreConsole.FindItems(backup, "Farm");

    DisplayThisAndChildrensNames(list[0],0);

    foreach (SPBackupRestoreObject oBURO in list)
    {
        Console.WriteLine("Name: " + oBURO.DisplayName);
        foreach (SPBackupRestoreObject oBUROchild in oBURO.Children)
        {
            Console.WriteLine("Name: " + oBUROchild.DisplayName);
        }
    }

private static void DisplayThisAndChildrensNames(SPBackupRestoreObject component, Int32 depth)
{
    Int32 currentDepth = 0;
    while (currentDepth < depth)
    {
        Console.Write("\t");
        currentDepth++;
    }
    Console.Write("Name: " + component.DisplayName +"\n");

    foreach (SPBackupRestoreObject oChild in component.Children)
    {
        DisplayThisAndChildrensNames(oChild, depth+1);
    }
}
Shared Sub Main(ByVal args() As String)
    Dim settings As SPBackupSettings = CType(SPBackupRestoreSettings.GetBackupSettings("\\server\Backups", "full"), SPBackupSettings)
    Dim backup As Guid = SPBackupRestoreConsole.CreateBackupRestore(settings)

    Dim list As SPBackupRestoreObjectCollection = SPBackupRestoreConsole.FindItems(backup, "Farm")

    DisplayThisAndChildrensNames(list(0),0)

    For Each oBURO As SPBackupRestoreObject In list
        Console.WriteLine("Name: " & oBURO.DisplayName)
        For Each oBUROchild As SPBackupRestoreObject In oBURO.Children
            Console.WriteLine("Name: " & oBUROchild.DisplayName)
        Next oBUROchild
    Next oBURO
End Sub
Private Shared Sub DisplayThisAndChildrensNames(ByVal component As SPBackupRestoreObject, ByVal depth As Int32)
    Dim currentDepth As Int32 = 0
    Do While currentDepth < depth
        Console.Write(vbTab)
        currentDepth += 1
    Loop
    Console.Write("Name: " & component.DisplayName & vbLf)

    For Each oChild As SPBackupRestoreObject In component.Children
        DisplayThisAndChildrensNames(oChild, depth+1)
    Next oChild
End Sub

Siehe auch

Referenz

SPBackupRestoreConsole Klasse

SPBackupRestoreConsole-Member

Microsoft.SharePoint.Administration.Backup-Namespace