TxFileManager 1.4.0

Transactional File Manager is a .NET API 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 (works with System.Transactions.TransactionScope). See GitHub project for more info: https://github.com/chinhdo/txFileManager

Install-Package TxFileManager -Version 1.4.0
dotnet add package TxFileManager --version 1.4.0
<PackageReference Include="TxFileManager" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TxFileManager --version 1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

.NET Transactional File Manager is a .NET 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();
} 

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.
  • 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, join this project and contribute yourself.

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.

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);

    scope1.Complete();
} 

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, you can also 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);

Release Notes

Version 1.4

  • 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

.NET Transactional File Manager is a .NET 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();
} 

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.
  • 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, join this project and contribute yourself.

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.

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);

    scope1.Complete();
} 

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, you can also 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);

Release Notes

Version 1.4

  • 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

Release Notes

* 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

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TxFileManager:

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

GitHub repositories (1)

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

Repository Stars
Warewolf-ESB/Warewolf
Effortless Microservice Design and Integration. This repository includes the code-base for the Warewolf Studio and Server.

Version History

Version Downloads Last updated
1.4.0 1,604 3/29/2020
1.3.0 94,932 8/24/2013
1.2.1 3,328 12/6/2011
1.1.0.25 1,001 5/4/2011