SPBackupRestoreConsole.DiskSizeRequired - Méthode (Guid, SPBackupRestoreObject)
Obtient la quantité d'espace disque nécessaire pour sauvegarder le nœud spécifié (et ses enfants) dans l'arborescence des composants dans l'opération de sauvegarde spécifiée.
Espace de noms : Microsoft.SharePoint.Administration.Backup
Assembly : Microsoft.SharePoint (dans Microsoft.SharePoint.dll)
Syntaxe
'Déclaration
Public Shared Function DiskSizeRequired ( _
id As Guid, _
node As SPBackupRestoreObject _
) As ULong
'Utilisation
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
)
Paramètres
id
Type : System.GuidID Guid de la SPBackupRestoreConsoleObject qui représente l'opération de sauvegarde.
node
Type : Microsoft.SharePoint.Administration.Backup.SPBackupRestoreObjectSPBackupRestoreObject qui représente le composant qui sera sauvegardé si l'opération identifié par id .
Valeur renvoyée
Type : System.UInt64
UInt64 qui représente l'espace, en octets, nécessaire pour l'opération de sauvegarde.
Remarques
La méthode DiskSizeRequired totalise les valeurs de DiskSizeRequired de tous les objets inclus dans l'opération de sauvegarde. Il ajoute également les octets de 1K pour garantir qu'elle retourne toujours un minimum de 1 Ko.
Si MaxValue() est retourné, id ne contient pas un objet de sauvegarde valide.
Exemples
L'exemple suivant montre la méthode DiskSizeRequired est utilisée pour déterminer si le volume de sauvegarde dispose de suffisamment d'espace pour contenir les composants à sauvegarder. Pour l'exemple complet et une description détaillée de ce dernier, consultez 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