Q: I have a lot of file operations that I want to execute as a batch, and I want these operations to use the standard Windows® progress UI. I know that I can do all of the file operations using the classes in the System.IO namespace, but then I need to create my own progress UI, which means that the work I'm going to do is much heavier than I thought. I noticed that Windows vista® contains a new ifileoperations interface, but I don't see any examples that show how to use that interface from managed code. How is it implemented?
Q: I have a lot of file operations that I want to execute as a batch, and I want these operations to use the standard Windows® progress UI. I know that I can do all of the file operations using the classes in the System.IO namespace, but then I need to create my own progress UI, which means that the work I'm going to do is much heavier than I thought. I noticed that Windows vista® contains a new ifileoperations interface, but I don't see any examples that show how to use that interface from managed code. How is it implemented?
A: Windows Vista actually includes a new replication engine that fully supports the work you want to accomplish. However, you may have previously existing features to meet your needs. For example, if you want to copy, move, rename, or delete a single file or directory, you can take advantage of shfileoperation (provided by Shell32.dll), which has been encapsulated by the Visual basic® runtime. If you are using Visual Basic 2005, you can simply use the features in the My namespace, such as:
A: Windows Vista actually includes a new replication engine that fully supports the work you want to accomplish. However, you may have previously existing features to meet your needs. For example, if you want to copy, move, rename, or delete a single file or directory, you can take advantage of shfileoperation (provided by Shell32.dll), which has been encapsulated by the Visual basic® runtime. If you are using Visual Basic 2005, you can simply use the features in the My namespace, such as:
My.Computer.FileSystem.CopyDirectory (
SourcePath, DestinationPath, Uioption.alldialogs)
Doing the same task in C # requires a little more work, that is, adding a reference to the Microsoft.VisualBasic.dll (from the microsoft®.net Framework installation directory) and using the following code:
Using
Microsoft.VisualBasic.FileIO;
...
Filesystem.copydirectory (
SourcePath,
DestinationPath, uioption.alldialogs);
The run produces a progress UI that is the same as you would see when you performed the same file operation from Windows Explorer. In fact, when running on Windows Vista, a new Window Vista Progress UI is automatically obtained, as shown in Figure 1.
Figure 1 Windows Vista Progress dialog box