Transactional File System


Microsoft strongly recommends developers investigate utilizing the discussed alternatives (or in some cases, investigate other alternatives) rather than adopting an API platform which may not be available in future versions of Windows.


Microsoft introduced Transactional NTFS (TxF) with Windows Vista. This enabled developers to make a number of file system operations and they would need to complete all or everything is rolled back (like in database transactions)

It uses unmanaged C++ operations from the Kernel32.dll. Also the Distributed Transaction Coordinator is used for managing the transaction.


Ever wanted to process a set of files as a whole? What if the last of 100 files is not moved / deleted / written? You would need to do a corrective action. What if the corrective action fails?


I’m investigating the TxF for reading and moving a set of files. The files need to be parsed, loaded into a database and archived as a set. When a file fails every file needs to be left in the input folder. This can be achieved by starting a transactionscope and completing it when everything succeeds.

using (var scope = new TransactionScope()) {
    foreach (var file in files) {
        var source = Path.Combine(directory, file);
        using(var stream = TransactedFile.Open(source, 
                    FileMode.Open, FileAccess.Read, FileShare.None))
            // read file and put in database
        var destination = Path.Combine(archive, file);
        TransactedFile.Move(source, destination);

Again: Microsoft is planning to deprecate the TxF API’s. Maybe if we all start using it Microsoft will hang on to it.


Transaction File System wrappers on github
Alternatives to using Transactional NTFS on MSDN

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.