Search code examples
c#restoreopenfiledialogsmo

Use SMO to locate correct backup path


I am developing a software using a MSSQL database for holding the data. In the program I implemented a function for creating a backup with SMO.

Now I am trying to implement a restore function. It works without any problems when the user has to insert the path manually. But I want to implement a select file dialog like this one the SQL Server Management Studio (SSMS) is opening when selecting a custom medium (see on the screenshot). SSMS Select dialog

I already found the Microsoft.SqlServer.Management.Smo.Server class with the method EnumDirectories, but it returns only directory names and no files. When I confirm the selection I need the path in format C:\Directory\FileName.bak.

Is it possible to meet my needs with using SMO?


Solution

  • Many months ago I found a solution. I just developed a custom SelectFileDialog which is able to connecto to SQL server and work with the following SQL functions:

    For searching available drives:

    exec xp_fixeddrives
    

    For reading folders and files:

    exec xp_dirtree 'PATH', 1, 1
    

    The PATH variable is dynamicly replaced depends on which folder is expanded by the user. It works without problems.