共用方式為


ReadFileList 方法

Returns the list of database files on the targeted media.

命名空間:  Microsoft.SqlServer.Management.Smo
組件:  Microsoft.SqlServer.SmoExtended (在 Microsoft.SqlServer.SmoExtended.dll 中)

語法

'宣告
Public Function ReadFileList ( _
    srv As Server _
) As DataTable
'用途
Dim instance As Restore
Dim srv As Server
Dim returnValue As DataTable

returnValue = instance.ReadFileList(srv)
public DataTable ReadFileList(
    Server srv
)
public:
DataTable^ ReadFileList(
    Server^ srv
)
member ReadFileList : 
        srv:Server -> DataTable 
public function ReadFileList(
    srv : Server
) : DataTable

參數

傳回值

型別:System.Data. . :: . .DataTable
A DataTable object that specifies the list of database files.

備註

The restore instance must declare a DeviceType before calling this method. Otherwise, an exception will be thrown.

範例

The following code example demonstrates how to create a backup file for the AdventurewWorks database and read the columns of each file in the backup with the Restore.ReadFileList method.

VB

Dim srv As Server = New Server()
Dim res As Restore = New Restore()
Dim backup As Backup = New Backup()
Dim dt As DataTable

backup.Devices.AddDevice("C:\AdventureWorks2008R22008R2Backup.bak", DeviceType.File)
backup.Database = "AdventureWorks2008R22008R2"
backup.Action = BackupActionType.Database
backup.Initialize = True
backup.SqlBackup(srv)

res.Devices.AddDevice("C:\AdventureWorks2008R22008R2Backup.BAK", DeviceType.File)
dt = res.ReadFileList(srv)

For Each r As DataRow In dt.Rows
   For Each c As DataColumn In dt.Columns
      Console.WriteLine(c.ToString + " = " + r(c).ToString())
   Next
Next

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$res = new-object Microsoft.SqlServer.Management.Smo.Restore
$backup = new-object Microsoft.SqlServer.Management.Smo.Backup

$backup.Devices.AddDevice("C:\AdventureWorks2008R22008R2Backup.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$backup.Database = "AdventureWorks2008R22008R2"
$backup.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$backup.Initialize = $TRUE
$backup.SqlBackup($srv)

$res.Devices.AddDevice("C:\AdventureWorks2008R22008R2Backup.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$dt = $res.ReadFileList($srv)

foreach($r in $dt.Rows)
{
   foreach ($c in $dt.Columns)
   {
      Write-Host $c "=" $r[$c]
   }
}