473,473 Members | 3,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

File copy with progress

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
5 4897
"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
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
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
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
"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 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: GK1402 | last post by:
I am writing a web app that will copy large files (250-3,000 MB) and wanted to know the easiest way to implement some sort of progress bar? Each copy will only have one file, but I would like a...
2
by: Ted Duross | last post by:
Hi, I’ve created an educational software application accessed by students from a central server. On Start-Up the application reads an XML file that stores student progress records. This XML...
8
by: Randy | last post by:
Hi, is it possible to show the progress of a big file being copied e.g. in a "progressbar"? I tried to use file.copy - but this seems to make no sense :-( Thanks in advance, Randy
11
by: Stephan Steiner | last post by:
Hi Generally, FileInfo fi = new FileInfo(path); long size = fi.Length; gets you the length of a file in bytes. However, when copying files, even while the copy operation is still in...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
4
by: hzgt9b | last post by:
Usig VB .NET 2003, I'm writing a simple app that copies 1 or more files. Requiremtns state that I need two progress bars one for current file copy progress and one for overall progress. My...
9
by: Alan T | last post by:
Is it possible to copy a file from one location to another? eg. from C:\Temp\Document\TestDoc.doc to C:\Deploy\Document\TestDoc.doc
2
by: durumdara | last post by:
Hi! I want to check my zip file writings. I need some callback procedure to show a progress bar. Can I do that? I don't want to modify the PyLib module to extend it, because if I get another...
6
by: Michael | last post by:
I need to copy a huge file (around 300Mb) from a mapped network drive to another. I have created a console application and used System.IO.File.Copy function. But I want to know the process of...
6
by: Johnny Jörgensen | last post by:
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.