By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,397 Members | 2,515 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,397 IT Pros & Developers. It's quick & easy.

File copy with progress

P: n/a
Using File.Copy in the System.IO namespace, it's easy to copy one or more
files.

But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with the
progress?

Same goes for deleting files...

Cheers,
Johnny J.
Oct 11 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:OY****************@TK2MSFTNGP04.phx.gbl...
Using File.Copy in the System.IO namespace, it's easy to copy one or more
files.

But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with the
progress?

Same goes for deleting files...
This can be achieved by means of a call to the Shell function
ShFileOperation. You can do this from your .Net program by means of Platform
Invoke. The declaration, along with some sample code, can be found at
pinvoke.net:
http://www.pinvoke.net/default.aspx/...Operation.html

Oct 11 '08 #2

P: n/a
Thanks a lot, Alberto, I'll look into that.

/Johnny J.


"Alberto Poblacion" <ea******************************@poblacion.orgskr ev i
meddelandet news:Ox**************@TK2MSFTNGP02.phx.gbl...
"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:OY****************@TK2MSFTNGP04.phx.gbl...
>Using File.Copy in the System.IO namespace, it's easy to copy one or more
files.

But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with
the progress?

Same goes for deleting files...

This can be achieved by means of a call to the Shell function
ShFileOperation. You can do this from your .Net program by means of
Platform Invoke. The declaration, along with some sample code, can be
found at pinvoke.net:
http://www.pinvoke.net/default.aspx/...Operation.html

Oct 11 '08 #3

P: n/a
On Oct 11, 5:42*pm, "Johnny Jörgensen" <j...@altcom.sewrote:
Using File.Copy in the System.IO namespace, it's easy to copy one or more
files.

But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with the
progress?

Same goes for deleting files...

Cheers,
Johnny J.
Yes, using P/Invoke with SHFileOperation API is the long and risky way
to write the whole code error-free, that's why My namespace in VB.NET
provides a well-wrapper for this:

My.Computer.FileSystem.CopyFile("source","dest", _
True,FileIO.UICancelOption.DoNothing)

The third parameter, which is "showUI", lets you to view native dialog
while copying is in progress.

http://msdn.microsoft.com/en-us/libr...yf(VS.80).aspx

Though yours is cross-post, you can call the same function in C# by
referencing it to Microsoft.VisualBasic.dll from .NET tab in "Add
Reference" menu with the following code:

using Microsoft.VisualBasic.Devices;

Computer copyfile = new Computer();
//Pass parameters below including showUI
copyfile.FileSystem.CopyFile(...);

Hope this helps,

Onur Güzel

Oct 11 '08 #4

P: n/a
My.Computer.FileSystem.CopyFile("source", "destination",
Microsoft.VisualBasic.FileIO.UIOption.AllDialogs,
FileIO.UICancelOption.DoNothing)
"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:uU**************@TK2MSFTNGP06.phx.gbl...
Thanks a lot, Alberto, I'll look into that.

/Johnny J.


"Alberto Poblacion" <ea******************************@poblacion.orgskr ev
i meddelandet news:Ox**************@TK2MSFTNGP02.phx.gbl...
>"Johnny Jörgensen" <jo**@altcom.sewrote in message
news:OY****************@TK2MSFTNGP04.phx.gbl...
>>Using File.Copy in the System.IO namespace, it's easy to copy one or
more files.

But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with
the progress?

Same goes for deleting files...

This can be achieved by means of a call to the Shell function
ShFileOperation. You can do this from your .Net program by means of
Platform Invoke. The declaration, along with some sample code, can be
found at pinvoke.net:
http://www.pinvoke.net/default.aspx/...Operation.html

Oct 11 '08 #5

P: n/a
On Oct 11, 6:31*pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Oct 11, 5:42*pm, "Johnny Jörgensen" <j...@altcom.sewrote:
Using File.Copy in the System.IO namespace, it's easy to copy one or more
files.
But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with the
progress?
Same goes for deleting files...
Cheers,
Johnny J.

Yes, using P/Invoke with SHFileOperation API is the long and risky way
to write the whole code error-free, that's why My namespace in VB.NET
provides a well-wrapper for this:

My.Computer.FileSystem.CopyFile("source","dest", _
True,FileIO.UICancelOption.DoNothing)
Minor correction related to code above from myself, use that instead:

My.Computer.FileSystem.CopyFile _
("C:\source.txt", _
"C:\folder\dest.txt",
Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, _
FileIO.UICancelOption.DoNothing)

HTH,

Onur Güzel


Oct 11 '08 #6

P: n/a
"Johnny Jörgensen" <jo**@altcom.seschrieb:
Using File.Copy in the System.IO namespace, it's easy to copy one or more
files.

But I wonder: Is it possible to get windows to display its File Copy
Progress dialog at the same time - or alternatively get callbacks with the
progress?
In addition to the other replies:

Wrapper around 'CopyFileEx' using the progress callback (suitable for
copying single files):

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/Transactions.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Oct 11 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.