.NET: How to copy files using Windows “Copy Files” dialog

青春壹個敷衍的年華 提交于 2019-12-04 13:01:16

In order to use the "Windows 'Copy Files' Dialog" you will be required to invoke "Windows platform specific libraries."

SHFileOperation, it is well supported by the standard .NET framework. Add a reference to Microsoft.VisualBasic.dll and use the Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory() method. Several overloads are available that allows you to control what the UI looks like and how to handle errors.

Google for IProgressDialog - this is an Interface that gives you the functionality that you request

Maybe you'll find the needed functionality at the Windows API Code Pack

If everything else fails, it may work the ugly way: create an invisible Windows Explorer window, and manipulate it to start a copying process.

In .NET you can make your own dialog.

It's not necessarily a difficult task though:

  • If you have VS2005 then unpack the VS2005ImageLibrary.zip located at C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary on a 64 bit system or C:\Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary on a 32 bit system.

  • Once you have unpacked the zip file, there will several animated GIF's of the file copy dialog's animation. These also come in .AVI format.

  • Choose one of the animated GIFs.

  • Create a dialog with a picture box on it. Assign the GIF to the picture box's image property.

  • Add a label below the animation to specify what file is being copied.

  • Drive the file-copy operation using threads updating the dialog as necessary.

The problem is that it's not really "Windows's Copy Files' Dialog", it's Explorer's dialog. So, it's have to find a way to programmatically control Explorer. (May be possible via COM or WMI)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!