Поделиться через


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

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.

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 Customizing Development Settings.

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, choose Framework 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.

Example

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,
            UIOption.AllDialogs);
    }
}

See Also

Other Resources

File System and the Registry (C# Programming Guide)