How to bring up the built-in File Copy dialog?

前端 未结 2 1928
粉色の甜心
粉色の甜心 2020-11-28 11:28

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 t

2条回答
  •  孤独总比滥情好
    2020-11-28 11:40

    Answer taken from: here

    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)
    

    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);
    

    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. Dialog

提交回复
热议问题