SPBackupRestoreConsole.DiskSize 方法
(作为out参数) 获取一个卷和对用户可用的空间量上的总磁盘空间。
命名空间: Microsoft.SharePoint.Administration.Backup
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
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
类型:System.String一个路径,可能是 UNC 路径,其空间信息时所需的卷上。
freeBytesAvailable
类型:System.UInt64当此方法返回时,包含DiskSize表示可用在dir所在的位置,被称为DiskSize的上下文中对用户的卷上的总字节数。不经初始化就传递此参数。
totalBytes
类型:System.UInt64当此方法返回时,包含DiskSizedir所在的卷上的总字节数表示。不经初始化就传递此参数。
返回值
类型:System.Int32
0,如果报告磁盘大小尝试失败 ;否则为其它Int32,表示操作成功。
备注
通常, dir是其中要存储备份,但可以使用位于同一卷上的任何有效路径, out参数将返回相同的值的路径。
示例
下面的示例演示用来确定备份卷是否有足够的空间来存放要备份的组件的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