Share via


SPBackupRestoreObjectCollection.Item property

Returns the object at the specified index in the collection.

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

Syntax

'Declaration
Public ReadOnly Property Item ( _
    index As Integer _
) As SPBackupRestoreObject
    Get
'Usage
Dim instance As SPBackupRestoreObjectCollection
Dim index As Integer
Dim value As SPBackupRestoreObject

value = instance.Item(index)
public SPBackupRestoreObject this[
    int index
] { get; }

Parameters

  • index
    Type: System.Int32

    An Int32 that specifies the index of the object in the collection.

Property value

Type: Microsoft.SharePoint.Administration.Backup.SPBackupRestoreObject
The SPBackupRestoreObject object at the specified index.

Examples

The following shows the Item indexer being used in a method that will ensure that the component name submitted by a user uniquely identifies a single component to be the top of the tree of components that will be processed by a backup or restore operation. For the full example and a detailed discussion of it, see 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

See also

Reference

SPBackupRestoreObjectCollection class

SPBackupRestoreObjectCollection members

Microsoft.SharePoint.Administration.Backup namespace