.NET Transactional File Manager is a .NET Standard library that allows you to enlist file operations (file/folder copies, writes, deletes, appends, etc.) in distributed transactions.
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
db.ExecuteNonQuery(insertSql);
scope1.Complete();
}
Support the following file operations in transactions:
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.
This started out as a blog post. It was hosted on CodePlex and migrated to GitHub in 3/2020.
Additional contributors: @gvas, AirBreather.
dotnet add package TxFileManager
IFileManager fm = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
{
// Copy a file
fm.Copy(srcFileName, destFileName);
scope1.Complete();
}
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".
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.
Yes - it's been tested for that.
Regardless of the specified IsolationLevel, the effective IsolationLevel is ReadUncommitted.
See Chinh's blog post: Include File Operations in Your Transactions Today with IEnlistmentNotification
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);
dotnet test
)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.
Please suggest your features using the Issues list.