.NET Standard 2.0
dotnet add package TxFileManager --version
NuGet\Install-Package TxFileManager -Version
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TxFileManager" Version="" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TxFileManager --version
#r "nuget: TxFileManager,"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install TxFileManager as a Cake Addin
#addin nuget:?package=TxFileManager&version=

// Install TxFileManager as a Cake Tool
#tool nuget:?package=TxFileManager&version=

Transactional File Manager is a .NET Standard 2.0 library that supports including file system operations such as file copy, move, delete, append, etc. in a transaction. It's an implementation of System.Transaction.IEnlistmentNotification.

This library allows you to wrap file system operations in transactions like this:

// Wrap a file copy and a database insert in the same transaction
IFileManager fm = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
    // Copy a file
    fm.Copy(srcFileName, destFileName);

    // Insert a database record


Current features

Support the following file operations in transactions:

  • AppendAllText: Appends the specified string the file, creating the file if it doesn't already exist.
  • Copy: Copy a file to another file.
  • Delete: Delete a file.
  • Move: Move a file.
  • CreateDirectory: Create a directory.
  • DeleteDirectory: Delete a directory.
  • MoveDirectory: Move a directory.
  • Snapshot: Take a snapshot of the specified file. The snapshot is used to rollback the file later if needed.
  • WriteAllBytes: Write the specified bytes to the file.
  • WriteAllText: Write the specified text content to the file.

If you have any suggestions for enhancements or bug reports please use the Issues list. Better yet, if possible join this project and contribute.

This library is available as a NuGet package. The current/latest release is 1.4.

This started out as a blog post. It was hosted on CodePlex and migrated to GitHub in 3/2020.

Additional contributors: @gvas, AirBreather.

Quick Start

  1. Add a reference to TxFileManager
dotnet add package TxFileManager
  1. Start writing code
IFileManager fm = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
    // Copy a file
    fm.Copy(srcFileName, destFileName);


Frequently Asked Questions

How do I run tests?

In a PowerShell/Command window:

dotnet test

In Visual Studio, open Test/Text Explorer and choose Run All Tests (or CTRL-R, A)

How do I reference this library?

The recommended method is to add a NuGet reference:

dotnet add package TxFileManager

Or Use Visual Studio's Manage NuGet Packages to add. Search for "TxFileManager".

Can I reuse instances of TxFileManager?

It's not expensive to create new instances of TxFileManager as needed. There's a bit of overhead (like creating instances of any small class) but not much.

On the other hand, it's totally safe to re-use the same instance for multiple transactions, even nested transactions.

Is TxFileManager Thread Safe?

Yes - it's been tested for that.

Which IsolationLevel's are supported?

Regardless of the specified IsolationLevel, the effective IsolationLevel is ReadUncommitted.

How does TxFileManager work?

See Chinh's blog post: Include File Operations in Your Transactions Today with IEnlistmentNotification

Where are temporary files/directories kept?

By default, the path returned by Path.GetTempPath() is used to keep temporary files/directories used by TxFileManager. However, you can override that and have TxFileManager use another temp path:

IFileManager fm = new TxFileManager(myTempPath);

How do I contribute to the project?

  • Fork the repo
  • Create a branch such as my-new-feature
  • Make your change/fix and associated unit tests and commit
  • Run the tests (dotnet test)
  • Open a Pull Request (PR) to the "master" branch

Notes: A release branch will be created out of the master branch when a release is made. The master branch will contain the latest features being added/tested for the next release.

Nuget Releases

Version 1.4 (released 3/2020)

  • Convert to xUnit tests
  • Add support for custom temp paths to address issues with file/dir operations accross filesystems
  • Fix for resource leak in TxFileManager._txEnlistment
  • Target .NET Standard 2.0
  • Additional testing for .NET Core on Ubuntu
  • Additional stress testing both on Windows and Ubuntu
  • Created Github workflow to automatically build/test on ubuntu
  • Added FxCop static analysis

Version (released 7/21/2021)

Please suggest your features using the Issues list.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on TxFileManager:

Package Downloads

File system-based (FileSystemWatcher) transport component to be used as a base for transports for Micro.NET


Bnsights.Providers.File.FileSystem contains a BaseFileProvider Implementation for FileSystem Bnsights Business Solutions Framework (BBSF) Package.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on TxFileManager:

Repository Stars
Lightweight utility for organizing the taskbar through groups
Effortless Microservice Design and Integration. This repository includes the code-base for the Warewolf Studio and Server.
Version Downloads Last updated 10,198 7/22/2021
1.4.0 11,980 3/29/2020
1.3.0 186,276 8/24/2013
1.2.1 7,570 12/6/2011 1,613 5/4/2011

- Bug fix Async code (Issue #27)
- Added new operations: CopyDirectory, MoveDirectory
- Added Encoding support to WriteAllText, AppendAllText
- Nuget package icon
- Misc refactors/clean-up