473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file copy question

hello,

i want to know how can i copy a file in a way if it was stopped for a reason
it can continue from the last point just like what torrents and file
download managers do?
thanks..

Aug 31 '07 #1
4 1244
"Jassim Rahma" <jr****@hotmail.comwrote in message
news:0F**********************************@microsof t.com...
i want to know how can i copy a file in a way if it was stopped for a
reason it can continue from the last point just like what torrents and
file download managers do?
Hello Jassim,

This could be done in various ways but the most straightforward one is to
have a FileStream [1] instance of your target file, write data to it from
the source and close the Stream when necessary. To resume, open the
FileStream again and seek to the last written byte and continue transferring
data. You can make use of the Position and Length properties or the Seek
method of the FileStream class.

[1] http://msdn2.microsoft.com/en-us/lib...ilestream.aspx

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info | www.aeroxp.org

Aug 31 '07 #2
Jassim Rahma wrote:
hello,

i want to know how can i copy a file in a way if it was stopped for a
reason it can continue from the last point just like what torrents and
file download managers do?
It depends on how you are copying the file. The shell doesn't provide a
built-in way to do this, AFAIK. But if you are writing your own copy
code (which is simple enough), it should be a simple matter to look at
the file length of the destination, and use that to determine where to
resume copying. Just open the destination file for appending, and seek
in the source file to the length of the destination file before you
start reading.

Pete
Aug 31 '07 #3
Hi,

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Jassim Rahma wrote:
>hello,

i want to know how can i copy a file in a way if it was stopped for a
reason it can continue from the last point just like what torrents and
file download managers do?

It depends on how you are copying the file. The shell doesn't provide a
built-in way to do this, AFAIK. But if you are writing your own copy code
(which is simple enough), it should be a simple matter to look at the file
length of the destination, and use that to determine where to resume
copying. Just open the destination file for appending, and seek in the
source file to the length of the destination file before you start
reading.
In addition you should verify that the source file is the same that the file
you were copying the first time.
Aug 31 '07 #4
Ignacio Machin ( .NET/ C# MVP ) wrote:
In addition you should verify that the source file is the same that the file
you were copying the first time.
Heh...well, there's a whole host of things I left out, all related to
the above (the question of whether the source file is the same is a
whole thread unto itself). I was just discussing the "how to resume"
aspect, not the "whether to resume".

But yes I agree, one should verify that resuming the copy is the right
thing to do before actually resuming it.

Pete
Aug 31 '07 #5

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

Similar topics

0
2078
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
2
4043
by: Robert W. | last post by:
I'm writing a WinForms app that copies files to Pocket PC using the RAPI 'CopyFileToDevice' method. If there are no interruptions then everything works perfectly. But in testing, I've...
5
1206
by: Washington | last post by:
Is possible to copy file from some server for. e.g. brinkster to computer (on specified location) programmatically? I am trying to make some automatic update of my application... Thanks :)
1
1342
by: needin4mation | last post by:
Hi, foreach (ListViewItem item in listViewFiles.Items) { MessageBox.Show(item.SubItems.Text + ", " + item.SubItems.Text); string source=item.SubItems.Text; string...
2
3751
by: Stephen Witter | last post by:
I had previously posted this on the security ng, but haven't had a hit so I was wondering if someone here would be willing to take a stab. I am trying to copy a file to a network drive. I can do...
8
2906
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm...
8
2022
by: sore eyes | last post by:
Hi I just downloaded the free Watcom compiler and am having a little trouble with File IO http://www.openwatcom.org/index.php/Download I downloaded the following example, commented out the...
2
1317
by: Jeff | last post by:
....hope this question is on the right ng. The code below works to copy all files and folders from D:\Template to a new location that is specified by the user. Is there any easy way to modify...
1
4248
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have problem with copying large number of files. Here is my code: foreach (FileInfo file in files) {...
7
1001
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi just wondering if there is any sample code to copy files from one directory into another with the code behind a button click event? Using c# vs2005. Thanks. -- Paul G Software engineer.
0
7265
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
7171
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
7547
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
7114
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
5693
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
3240
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
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1607
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 ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.