473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
6 9341
"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
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
"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 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...
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...
5
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.