共用方式為


SPBackupRestoreConsole.DiskSizeRequired method (Guid, SPBackupRestoreObject)

在樹狀目錄中指定的備份作業的元件取得備份指定的節點 (及其子項) 所需的磁碟空間量。

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

Syntax

'宣告
Public Shared Function DiskSizeRequired ( _
    id As Guid, _
    node As SPBackupRestoreObject _
) As ULong
'用途
Dim id As Guid
Dim node As SPBackupRestoreObject
Dim returnValue As ULong

returnValue = SPBackupRestoreConsole.DiskSizeRequired(id, _
    node)
public static ulong DiskSizeRequired(
    Guid id,
    SPBackupRestoreObject node
)

參數

傳回值

Type: System.UInt64
UInt64 代表的空間,以位元組為單位,所需的備份作業。

備註

DiskSizeRequired方法加總包含在備份作業中的所有物件的DiskSizeRequired值。它也會以確定它一定會傳回 1 K 至少要有 1 K 位元組。

會傳回MaxValue() ,如果id不包含有效備份物件。

Examples

下列範例會顯示被用來判斷備份的磁碟區是否有足夠空間可容納要備份的元件, DiskSizeRequired方法。完整範例和它的詳細的資訊,請參閱 < How to: Programmatically Back Up Content

private static Boolean EnsureEnoughDiskSpace(String location, Guid backup, SPBackupRestoreObject node)
{
    UInt64 backupSize = SPBackupRestoreConsole.DiskSizeRequired(backup, node);
    UInt64 diskFreeSize = 0;
    UInt64 diskSize = 0;
    Boolean hasEnoughSpace = true;

    try
    {
        SPBackupRestoreConsole.DiskSize(location, out diskFreeSize, out diskSize);
    }
    catch
    {
        diskFreeSize = diskSize = UInt64.MaxValue;
    }

    if (backupSize > diskFreeSize)
    {
        // Report through your UI that there is not enough disk space.
        Console.WriteLine("{0} bytes of space is needed but the disk hosting {1} has only {2}.", backupSize, location, diskFreeSize);
        Console.WriteLine("Please try again with a different backup location or a smaller component.");
        hasEnoughSpace = false;
    }
    else if (backupSize == UInt64.MaxValue || diskFreeSize == 0)
    {
        // Report through your UI that it cannot be determined whether there is enough disk space.
        Console.WriteLine("Cannot determine if that location has enough disk space.");
        Console.WriteLine("Please try again with a different backup location or a smaller component.");
        hasEnoughSpace = false;
    }
    return hasEnoughSpace;

}// end EnsureEnoughDiskSpace
Private Shared Function EnsureEnoughDiskSpace(ByVal location As String, ByVal backup As Guid, ByVal node As SPBackupRestoreObject) As Boolean
    Dim backupSize As UInt64 = SPBackupRestoreConsole.DiskSizeRequired(backup, node)
    Dim diskFreeSize As UInt64 = 0
    Dim diskSize As UInt64 = 0
    Dim hasEnoughSpace As Boolean = True

    Try
        SPBackupRestoreConsole.DiskSize(location, diskFreeSize, diskSize)
    Catch
        diskSize = UInt64.MaxValue
        diskFreeSize = diskSize
    End Try

    If backupSize > diskFreeSize Then
        ' Report through your UI that there is not enough disk space.
        Console.WriteLine("{0} bytes of space is needed but the disk hosting {1} has only {2}.", backupSize, location, diskFreeSize)
        Console.WriteLine("Please try again with a different backup location or a smaller component.")
        hasEnoughSpace = False
    ElseIf backupSize = UInt64.MaxValue OrElse diskFreeSize = 0 Then
        ' Report through your UI that it cannot be determined whether there is enough disk space.
        Console.WriteLine("Cannot determine if that location has enough disk space.")
        Console.WriteLine("Please try again with a different backup location or a smaller component.")
        hasEnoughSpace = False
    End If
    Return hasEnoughSpace

End Function ' end EnsureEnoughDiskSpace

請參閱

參照

SPBackupRestoreConsole class

SPBackupRestoreConsole members

DiskSizeRequired overload

Microsoft.SharePoint.Administration.Backup namespace