How to: Provide a Progress Dialog Box for File Operations (C# Programming Guide)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

You can provide a standard dialog box that shows progress on file operations in Windows if you use the CopyFile(String, String, UIOption) method in the Microsoft.VisualBasic namespace.

System_CAPS_ICON_note.jpg Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Personalizing the IDE.

To add a reference in Visual Studio

  1. On the menu bar, choose Project, Add Reference.

    The Reference Manager dialog box appears.

  2. In the Assemblies area, chooseFramework if it isn’t already chosen.

  3. In the list of names, select the Microsoft.VisualBasic check box, and then choose the OK button to close the dialog box.

The following code copies the directory that sourcePath specifies into the directory that destinationPath specifies. This code also provides a standard dialog box that shows the estimated amount of time remaining before the operation finishes.

        // The following using directive requires a project reference to Microsoft.VisualBasic.
        using Microsoft.VisualBasic.FileIO;

        class FileProgress
            static void Main()
                // Specify the path to a folder that you want to copy. If the folder is small, 
                // you won't have time to see the progress dialog box.
                string sourcePath = @"C:\Windows\symbols\";
                // Choose a destination for the copied files.
                string destinationPath = @"C:\TestFolder";

                FileSystem.CopyDirectory(sourcePath, destinationPath,

File System and the Registry (C# Programming Guide)