我将使用我的 winforms 应用程序通过网络复制一个大文件,并且我需要显示某种进度条。我没有编写自己的复制例程,而是认为简单地显示内置文件复制对话框可能会更好。
我还需要“复制完成”和“复制失败”通知。
我需要它在 Windows XP、Vista 和 7 上工作。有没有办法从我的 C# 代码中调用此功能?
答案摘自:here
Windows Vista 确实包含一个新的复制引擎,它完全支持您想要执行的操作。但是,以前现有的功能可能会满足您的需求。例如,如果要复制、移动、重命名或删除单个文件或目录,可以利用 SHFileOperation(从 shell32.dll 公开),它已由 Visual Basic® 运行时包装。如果您使用的是 Visual Basic 2005,则可以简单地使用 My 命名空间中的功能,例如:
My.Computer.FileSystem.CopyDirectory(
sourcePath, destinationPath, UIOption.AllDialogs)
在 C# 中完成同样的事情只需要多做一点工作,添加对 Microsoft.VisualBasic.dll(来自 Microsoft® .NET Framework 安装目录)的引用并使用如下代码:
using Microsoft.VisualBasic.FileIO;
...
FileSystem.CopyDirectory(
sourcePath, destinationPath, UIOption.AllDialogs);
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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)