Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

Does anyone know how to implement a rollback function in file copying when an exception is thrown.

Here are some conditions when I copy the files:
1. Copy the file to a shared folder
2. File is no greater than 3MB
3. File is an image file (jpg, jpeg, bmp, gif, png)
4. Prevention of file name duplicate is already implemented
5. OS is in Windows XP and higher
6. Code is on C# .Net 4.0 in Visual Studio 2010 Professional
7. Network connection is Local Area Network
8. Multiple files to copy

Please help.
Thanks in advance.
Posted
Updated 10-Jan-12 15:12pm
v2
Comments
[no name] 10-Jan-12 21:08pm    
If you are using File.Copy and an exception is thrown, the process doesn't complete anyway. Why do you need a rollback? Am I missing something?
unknowndentified10111 10-Jan-12 21:12pm    
I updated my question. Sorry for the confusion. Do you have any idea? Please I need help.

1 solution

Maintain a list of files that were successfully copied and delete them in the catch block for your exception handler. Is there something else you are not mentioning?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900