如何打开内置的文件复制对话框? [英] How to bring up the built-in File Copy dialog?

查看:172
本文介绍了如何打开内置的文件复制对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用我的winforms应用程序在网络上复制一个大文件,我需要显示某种进度条。而不是做自己的复制例程,我认为简单地显示内置的文件复制对话框可能会更好。

I'll be copying a large file over the network using my winforms app and I need to show some kind of progress bar. Rather than cook up my own copy routine, I was thinking that it might be better to simply show the built-in file copy dialog.

我还需要一个复制完成和复制失败通知。

I would also need a "Copy complete" and "Copy failed" notification.

我需要这样才能在Windows XP,Vista和7上工作。有没有一种方法可以从我的c#码?

I need this to work on Windows XP, Vista and 7. Is there a way to call to engage this functionality from my c# code?

推荐答案

答案取自: http://msdn.microsoft.com/en-us/magazine/cc163304.aspx


Windows Vista确实包含一个新的副本引擎,它支持您正在寻找的内容。但是,以前存在的功能可能会满足您的需求。例如,如果要复制,移动,重命名或删除单个文件或目录,则可以利用已由VisualBasic®运行时包装的SHFileOperation(从shell32.dll公开)。如果您使用Visual Basic 2005,您可以简单地使用我的命名空间中的功能,例如:

Windows Vista does indeed include a new copy engine that supports exactly what you're looking to do. However, it's possible that previously existing functionality may meet your needs. For example, if you want to copy, move, rename, or delete an individual file or directory, you can take advantage of SHFileOperation (exposed from shell32.dll), which is already wrapped by the Visual Basic® runtime. If you're using Visual Basic 2005, you can simply use functionality from the My namespace, for example:

 My.Computer.FileSystem.CopyDirectory(
   sourcePath, destinationPath, UIOption.AllDialogs)

完成同样的事情C#仅需要更多的工作,添加对Microsoft.VisualBasic.dll(从Microsoft®.NET Framework安装目录)的引用,并使用以下代码:

Accomplishing the same thing in C# involves only a little more work, adding a reference to Microsoft.VisualBasic.dll (from the Microsoft® .NET Framework installation directory) and using code such as the following:

using Microsoft.VisualBasic.FileIO;
...
FileSystem.CopyDirectory(
    sourcePath, destinationPath, UIOption.AllDialogs);

运行时,这将导致您会看到相同的进度UI,如果你做同样的Windows资源管理器中的文件操作。实际上,当在Windows Vista上运行时,您会自动获取新的Window Vista进度UI,如图1所示。

When run, this will result in the same progress UI you'd see if you were doing the same file operations from Windows Explorer. In fact, when running on Windows Vista, you automatically get the new Window Vista progress UI, as shown in Figure 1.

这篇关于如何打开内置的文件复制对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆