Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Restore.ReadFileList Method (Server)

 

Applies To: SQL Server 2016 Preview

Returns the list of database files on the targeted media.

Namespace:   Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.SmoExtended (in Microsoft.SqlServer.SmoExtended.dll)

public DataTable ReadFileList(
	Server srv
)

Parameters

srv
Type: Microsoft.SqlServer.Management.Smo.Server

A Server object that represents the instance of SQL Server that provides access to the targeted media.

Return Value

Type: 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.

Legacy Code Example

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:\AdventureWorks2012Backup.bak", DeviceType.File)
backup.Database = "AdventureWorks2012"
backup.Action = BackupActionType.Database
backup.Initialize = True
backup.SqlBackup(srv)

res.Devices.AddDevice("C:\AdventureWorks2012Backup.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:\AdventureWorks2012Backup.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$backup.Database = "AdventureWorks2012"
$backup.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$backup.Initialize = $TRUE
$backup.SqlBackup($srv)

$res.Devices.AddDevice("C:\AdventureWorks2012Backup.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]
   }
}
Return to top
Show:
© 2015 Microsoft