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


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

The easiest way to provide a standard Windows progress dialog box when you perform file operations is to use the FileSystem object that is provided 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 Visual Studio Settings.

To add a reference to Microsoft.VisualBasic.dll

  • In Visual Studio, open or create a project and then click Add Reference on the Project menu. On the .NET tab, select Microsoft.VisualBasic in the Component Name column.

To add a using directive

  • In your C# file, add the following line:

    using Microsoft.VisualBasic.FileIO;
    

Example

The following code copies the directory specified by sourcePath into the directory specified by destinationPath. It also provides a standard Windows progress dialog box that shows the estimated time remaining before the operation finishes.

// Requires project reference to Microsoft.VisualBasic
using Microsoft.VisualBasic.FileIO;
class FileProgress
{
    static void Main()
    {
        string sourcePath = @"C:\Users\public\documents\";
        string destinationPath = @"C:\testFolder";
        FileSystem.CopyDirectory(sourcePath, destinationPath,
            UIOption.AllDialogs);
    }
}

See Also

Other Resources

File System and the Registry (C# Programming Guide)