473,771 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ 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 4911
"Johnny Jörgensen" <jo**@altcom.se wrote in message
news:OY******** ********@TK2MSF TNGP04.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.o rgskrev i
meddelandet news:Ox******** ******@TK2MSFTN GP02.phx.gbl...
"Johnny Jörgensen" <jo**@altcom.se wrote in message
news:OY******** ********@TK2MSF TNGP04.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.se wrote:
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.Fil eSystem.CopyFil e("source","des t", _
True,FileIO.UIC ancelOption.DoN othing)

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.Visua lBasic.dll from .NET tab in "Add
Reference" menu with the following code:

using Microsoft.Visua lBasic.Devices;

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

Hope this helps,

Onur Güzel
Oct 11 '08 #4
My.Computer.Fil eSystem.CopyFil e("source", "destinatio n",
Microsoft.Visua lBasic.FileIO.U IOption.AllDial ogs,
FileIO.UICancel Option.DoNothin g)
"Johnny Jörgensen" <jo**@altcom.se wrote in message
news:uU******** ******@TK2MSFTN GP06.phx.gbl...
Thanks a lot, Alberto, I'll look into that.

/Johnny J.


"Alberto Poblacion" <ea************ *************** ***@poblacion.o rgskrev
i meddelandet news:Ox******** ******@TK2MSFTN GP02.phx.gbl...
>"Johnny Jörgensen" <jo**@altcom.se wrote in message
news:OY******* *********@TK2MS FTNGP04.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
ShFileOperatio n. 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.se schrieb:
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.zi p>

--
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
1221
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 way for the user to see how far the copy is. Thanks in advance!
2
7468
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 file stores DataSet information, one DataTable and a number of DataRows, one per student. Once finished the student’s DataRow is updated and the DataSet is written to the XML file.
8
18359
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
32587
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 progress, the filesize, as indicated in Windows Explorer or derived with the above two lines of code, will be the size of the file once the copy operation has completed. Is there a way to
0
3940
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
4
3364
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 problem is that I'm not sure how to obtain progress about a file as it is being copied. I've read some thread about using the SHFileOperation API but I'm lost as to how to implemt that in .NET. Can someone give me a pointer to some doco? Also an...
9
8243
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
5738
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 py, the changes are lost. This happening too if I copy the zip module to modify it. Any solution?
6
5083
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 this copying work. Is there any way? I am thinking that I can get the file size, but I don't know how to get the size copied. Thanks.
6
9362
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 alternatively get callbacks with the progress? Same goes for deleting files... Cheers,
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4007
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 we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.