问题描述
我会复制大文件在使用我的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#code搞这个功能?
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中确实包括一个新的复制引擎,支持你正在寻找到底该怎么做。但是,它可能是previously现有的功能可以满足您的需求。例如,如果要复制,移动,重命名或删除单个文件或目录,你可以利用SHFileOperation(来自shell32.dll中暴露的),这已经是包裹由VisualBasic®运行。如果您在使用Visual Basic 2005,您可以简单的使用功能,从我的命名空间,例如:
My.Computer.FileSystem.CopyDirectory(
sourcePath, destinationPath, UIOption.AllDialogs)
完成同样的事情在C#中只涉及更多一点的工作,增加提及Microsoft.VisualBasic.dll中(从Microsoft®.NET Framework安装目录),并使用code,如以下内容:
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上运行时,可以自动获得新的Windows 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.
这篇关于如何打开内置的文件复制对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!