Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

file copy question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jassim Rahma - 31 Aug 2007 15:37 GMT
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..
Stanimir Stoyanov - 31 Aug 2007 16:00 GMT
> 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/library/system.io.filestream.aspx

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info | www.aeroxp.org
Peter Duniho - 31 Aug 2007 17:45 GMT
> 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
Ignacio Machin ( .NET/ C# MVP ) - 31 Aug 2007 19:00 GMT
Hi,

>> hello,
>>
[quoted text clipped - 9 lines]
> 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.
Peter Duniho - 31 Aug 2007 19:11 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.