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

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

问题描述

我将使用我的 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?

推荐答案

答案来自:这里

Windows Vista 确实包含一个新的复制引擎,它完全支持您要执行的操作.但是,以前存在的功能可能会满足您的需求.例如,如果您想要复制、移动、重命名或删除单个文件或目录,您可以利用 SHFileOperation(从 shell32.dll 公开),它已经被 Visual Basic® 运行时包装了.如果您使用的是 Visual Basic 2005,则可以简单地使用 My 命名空间中的功能,例如:

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® .NE​​T 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);

运行时,这将产生与您在 Windows 资源管理器中执行相同文件操作时看到的相同进度 UI.实际上,在 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天全站免登陆