0

I have a scenario in my application is that i need to upload some files (Zip files) from the client to the server and in the server i want to extract the Zip file and replace those files which i getting from extracting the Zip file into some other folder.

The files which i need to be replaced is mostly dll files. So one thing that i need to ensure that either all files should be replaced or none of them get replaced.

Is there any way in C# to achieve this (like Transaction in SQL) ? If anything bad occurs while replacing files (Example: no memory space), every changes happened to the previous files should be rollbacked.

Hope you understand the problem.

Any help ?

Frebin Francis
  • 1,905
  • 1
  • 11
  • 19
  • possible duplicate of [C# - System.Transactions.TransactionScope](http://stackoverflow.com/questions/2273419/c-sharp-system-transactions-transactionscope) –  Mar 12 '15 at 10:34

2 Answers2

2

NTFS allows file system transactions, see https://msdn.microsoft.com/en-us/magazine/cc163388.aspx

embee
  • 1,007
  • 7
  • 15
  • @FrebinFrancis Just what kind of "server" uses FAT? –  Mar 12 '15 at 10:40
  • 2
    **MoveFileTransacted()** is being dropped. _[Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in future versions of Microsoft Windows](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365241(v=vs.85).aspx)_ –  Mar 12 '15 at 10:48
2

Having a quick poke around, only way I can see you doing this would be through https://msdn.microsoft.com/en-us/magazine/cc163388.aspx which involves some native code. Otherwise you could use a third party tool such as http://transactionalfilemgr.codeplex.com/

If you wanted to manage it yourself or go for a simpler approach, I would suggest backing up the existing files somewhere before trying to copy the new files. This could be in another folder or zipped up. Then if the copy fails, you handle this and revert all the files to their original state.

Whatever you choose, make sure you have plenty of logging so you can see what's happening and if/when something goes wrong :)

timothyclifford
  • 6,799
  • 7
  • 57
  • 85
  • 2
    Regarding your first link - **MoveFileTransacted()** is being dropped. _[Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in future versions of Microsoft Windows](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365241(v=vs.85).aspx)_ –  Mar 12 '15 at 10:49