SPBackupRestoreConsole.DiskSize method
取得總上的磁碟空間的磁碟區及使用者可用的空間量 (以out參數)。
Namespace: Microsoft.SharePoint.Administration.Backup
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Shared Function DiskSize ( _
dir As String, _
<OutAttribute> ByRef freeBytesAvailable As ULong, _
<OutAttribute> ByRef totalBytes As ULong _
) As Integer
'用途
Dim dir As String
Dim freeBytesAvailable As ULong
Dim totalBytes As ULong
Dim returnValue As Integer
returnValue = SPBackupRestoreConsole.DiskSize(dir, _
freeBytesAvailable, totalBytes)
public static int DiskSize(
string dir,
out ulong freeBytesAvailable,
out ulong totalBytes
)
參數
dir
Type: System.String路徑中,可能是 UNC 路徑,其空間資訊所需的磁碟區上。
freeBytesAvailable
Type: System.UInt64此方法傳回時,會包含代表可用、 dir所在,使用者會呼叫其內容DiskSize磁碟區上的總位元組DiskSize 。此參數會傳遞未初始化。
totalBytes
Type: System.UInt64此方法傳回時,會包含代表dir所在的磁碟區上的總位元組DiskSize 。此參數會傳遞未初始化。
傳回值
Type: System.Int32
0,如果報表磁碟大小嘗試失敗 ;否則一些其他Int32,這表示作業成功。
備註
一般而言, dir是其中您想要儲存備份,但可以使用相同的磁碟區上任何有效的路徑和out參數將會傳回相同值的路徑。
Examples
下列範例會顯示被用來判斷備份的磁碟區是否有足夠空間可容納要備份的元件, DiskSize方法。完整範例和它的詳細的資訊,請參閱 < 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