开发者

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

开发者 https://www.devze.com 2022-12-25 03:26 出处:网络
.NET: How can I copy the files using Windows \"Copy Files\" dialog. I need to bulk copy multiple files. Does there exists any .NET 2.0 library/method that allows me to do it 开发者_开发技巧in crosspla

.NET: How can I copy the files using Windows "Copy Files" dialog. I need to bulk copy multiple files. Does there exists any .NET 2.0 library/method that allows me to do it 开发者_开发技巧in crossplatform manner without invoking Windows platform specific libraries.

Thanks in advance.


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.


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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号