How can I use Transaction in FILE OPERATIONS?

createfiletransacted
transactional ntfs
file system transaction
transactional ntfs windows 10
transactional ntfs c#
ntfs transaction log
msdn ntfs
createtransaction

My program needs to treat some file operations as a unit, some of the important steps in a case are:

  1. delete a file in a directory.
  2. validate some data. if the data is invalid, roll back.
  3. Upload a file to the directory. if upload failed , roll back.
  4. commit changes.

I raise this requirement about transaction is because sometimes a user may use VPN to access my website, the VPN connection maybe very unstable.

If the 3rd step faild, the 1st file and the new uploaded file will all LOST.

some of my code:

        DeleteTheOlderDT(path, FileName);

        this.fuTemplateName.SaveAs(path + FileName);
        _t.FileName = FileName;

        if (!System.IO.File.Exists(path + FileName))
        {
            ArrayList ItemList = new ArrayList();
            ItemList.Add("Uploading failed, please upload again!");
            btlError.DataSource = ItemList;
            btlError.DataBind();
            _t.FileName = "";
            return;
        }

Transaction, to the directory. if upload failed , roll back. Given that it's not trivial to guarantee that both a file system and SQL operation either succeed or fail together, another approach can be used where each operation can happen independently but only the final operation in the sequence of operations "commits/registers" the overall action (in my case the overall action is that both the file and its metadata are stored successfully or not at all).

I never tried it for File system but there is nice article available on code project.

Please take a look http://www.codeproject.com/Articles/31270/A-Transactional-Repository-Implementation-in-NET

Hope it will resolve your problem.

How to Use Transactional NTFS, The file resource manager offers you the possibility to isolate a number of operations on a set of files in a transaction. Using the locks package it� By default EntityFramework Inserts, Updates or Deletes operations in a transaction, when you call SaveChanges () method of context object. EF starts a new transaction for each operation and completes the transaction when the operation finishes. EntityFramework 6.0 provides two new methods.

Windows Vista and newer support Transactional NTFS, which might help you out.

But really, you should consider reworking your logic - upload to a temporary file, and only delete the original file (and rename tempfile) if the upload succeeds.

Transactional NTFS, Transacted File Handles. Transactional NTFS (TxF) binds a file handle to a transaction. For operations that work on a handle (for example, the� Know how to view SQL Server transaction log with commercial utility. Step 1: Open & launch the SQL Server Transaction Log Reader; Step 2: Click on Open to add .ldf and associated .mdf file; Step 3: Choose Online or Offline Option to Scan ldf file data to the software; Step 4: After scanning .ldf file software allow you to preview .ldf file transactions

Integrating file operations into transactional memory, Using transactions ensures correctness of operation; in a series of file operations (done as a transaction), the operation will be committed if all the operations� Leave the database in read-only mode. Undo uncommitted transactions, but save the undo actions in a file so that recovery effects can be reversed. (RESTORE WITH STANDBY) Leaves the database in a standby state. This option is equivalent to using the STANDBY option in a Transact-SQLRESTORE statement.

file system operations within a transaction, This indicates that after the seek operation sets the file offset, all subsequent operations in the transaction on the same descriptor use the offset value from the � When using the drivers, each operation in the transaction must be associated with the session (i.e. pass in the session to each operation). Operations in a transaction use transaction-level read concern, transaction-level write concern, and transaction-level read preference.

.NET Transactional File Manager, Anyone who's ever developed anything connected to a database knows about transactions. Using a transaction we can group data operations� When you use transactions, you put locks on data that is pending for permanent change to the database. No other operations can take place on locked data until the acquired lock is released. You could lock anything from a single row up to the entire database. This is called concurrency, which means how the database handles multiple updates at one time.

Comments
  • I know I can let the user to upload the file again. But the best way in my case is use transaction like we always do in ado.net.
  • I'd rethink the flow of operations to prevent headaches: first of all upload the file in a temporary location, if the upload succeeds validate some data, if the data validates perform the delete & move the uploaded file to the right location.
  • Possible duplicate of How to write a transaction to cover Moving a file and Inserting record in database?
  • I think there's a way to solve this problem, cause this concept is very important. And database system is based on file system too. There should be a open-src framework or something.
  • Check links, which I added to my answer
  • THX, I also found that windows Vista/7, server2008 Natively support file transaction.
  • that's a good idea, but there're many other place needs do that too, so it's nessary to use a transaction, to make the code clearly.
  • ...then there's many other places where the code needs to be fixed ;-)