. NET related issues: IFileOperation in Windows Vista

Source: Internet
Author: User
Tags advantage

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.