Project Description
The project presents .NET 4.0 library NFile (different file/folder implementations).

Introduction to NFile

The project presents .NET 4.0 library NFile.
The library implements several types of "File" and "Folder" classes:
  • TemporaryFile implements temporary file. The file always will be deleted (in Dispose() or in ~TemporaryFile() finalizer methods).
  • TemporaryFolder implements temporary folder. The folder always will be deleted (in Dispose() or in ~TemporaryFolder() finalizer methods).

Nuget package can be found: http://nuget.org/packages/NFile.Framework

TemporaryFile Samples
            using (TemporaryFile temporaryFile = new TemporaryFile())
            {
                File.WriteAllText(temporaryFile.FileName, "[0]: test");
                File.AppendAllText(temporaryFile.FileName, "[1]: additional text");

                string allText = File.ReadAllText(temporaryFile.FileName);
                Assert.AreEqual("[0]: test" + "[1]: additional text", allText);
            }

TemporaryFolder Samples
            using (TemporaryFolder temporaryFolder = new TemporaryFolder())
            {
                string filePath = Path.Combine(temporaryFolder.Folder, "file1.txt");
                File.WriteAllText(filePath, "[0]: test");
                File.AppendAllText(filePath, "[1]: additional text");

                string allText = File.ReadAllText(filePath);
                Assert.AreEqual("[0]: test" + "[1]: additional text", allText);
            }

TemporaryCollection Samples
            string fileName;
            string folderName;
            using (var temporaryCollection = new TemporaryCollection())
            {
                ITemporaryFile file = temporaryCollection.AddFile();
                ITemporaryFolder folder = temporaryCollection.AddFolder();

                fileName = file.FileName;
                folderName = folder.Folder;

                Assert.IsTrue(File.Exists(fileName));
                Assert.IsTrue(Directory.Exists(folderName));
            }
            Assert.IsFalse(File.Exists(fileName));
            Assert.IsFalse(Directory.Exists(folderName));


Additional information on starting a new project is available here: Project Startup Guide.

Last edited Jul 29, 2012 at 9:16 PM by constructor, version 16