Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys, I have a scenario in my application where I need to transfer 20 files from a source location to a destination location (all local transfers), if one of the files fail to transfer, for whatever reason I need to roll back a transaction so that all the file remain in the source location and are gone from the destination. I have looked at transaction scope for this but I'm reading that maybe this is not the best approach for this. Has anyone any examples on how to achieve my goal. Thanks very much
Posted
Comments
DamithSL 8-Nov-14 4:05am    
how users download the files? is it asp.net web site?

There needs to be an exception that gets raised when there is a failure while transfering the files to the client (destination). So that would be like

C#
try {
  // send all the files
} catch (Exception er) {
  // exception was raised, 
  // if the exception was the File Not Transferred sort of thing
  // delete all of the Files from the Client.
}


This is a general case, where you attempt to do something, if error triggers, you delete (cancel, roll back) any changes that you've made on the clients computer. It is similar to a copy/paste function, upon Cancel click, the changes are removed and the computer is back in its initial stage.

Edit

While I was offline, I was thinking about a better solution for this problem. Which is, you can transfer the files over the internet connection and log each file that was transferred and the delivery report for it (either successfull or failure). Once you do this, you will be able to capture the details and resend the file that had a trouble. Because deleting the entire file set that was sent successfully and retrying to send the files to the client is not a good way. Just resend that one file.

Somehow you're still interested in the FileSystem transaction kind of thing, you can have a read at the Windows' Transactional NTFS[^]. Or read this MSDN magazine[^]. Or a simple Windows developer documentation for using Transactional NTFS[^]. Also note that there is a Transactional File Manager[^] available for you to use.

Good luck. :-)
 
Share this answer
 
v3
Comments
frostcox 8-Nov-14 4:08am    
Hey thanks for your response, The process will perform the operations in batches of 20, so the clients computer could have 100's of files there already. Is there any FileSystem transactions which you know about?
Afzaal Ahmad Zeeshan 8-Nov-14 5:13am    
Sorry for the delay. I have added an edit section in my answer for you to better understand this solution. Have a look at my answer now. :-)
frostcox 8-Nov-14 16:40pm    
Hey, thanks for the detailed answer, I will look into the Transactional File Manager and see if it fits my needs. I like the idea of logging so i will implement that aswell, thanks again.
Afzaal Ahmad Zeeshan 8-Nov-14 17:21pm    
You're most welcome.
Manas Bhardwaj 8-Nov-14 7:41am    
My 5!
 
Share this answer
 
Comments
Manas Bhardwaj 8-Nov-14 7:41am    
Nice +5!
DamithSL 8-Nov-14 7:55am    
Thank you, Manas

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