home | downloads | recipes | blogs | staff | about us | *

The Art of Lightning
Transactional NTFS C# CodeJames Zimmerman7/23/2007

Just cross linking to Matevz Gacnik's great code that leverages the new APIs in Vista/2008 server allowing NTFS to enlist in transactions.

This allows you to do neat things like this:

using (TransactionScope tsFile = new TransactionScope(TransactionScopeOption.Required))
{
   Console.WriteLine("Creating transacted file '{0}'.", filename);

   using (StreamWriter tFile = new StreamWriter(TransactedFile.Open(
          filename, 
          FileMode.Create, 
          FileAccess.Write, 
          FileShare.None)))
   {
      tFile.Write(String.Format("Random data. My filename is '{0}'.", 
          filename));
   }

   tsFile.Complete();
   Console.WriteLine("File '{0}' written.", filename);
}


Check it out
Jimmy Zimms is currently in stasis waiting for the release of Halo 3
 

Look for more blogs |

(c) 2001-2012 Stuart Williams, E-Mail Stuart Williams