This project has moved. For the latest updates, please go here.

FileStreamSave

Extension for simply saving a FileStream

Save()

string Save(string path, (optional)bool overwrite)
Details:
  • Saves FileStream to path then returns the saved file name
  • overwrite defaults to false if it is not specified
  • if overwrite is false or omitted and the file already exists, it will append a counter to the file name; file.txt, file1.txt, file2.txt, etc.
  • if overwrite is true it will overwrite any existing files
  • if the folder you are trying to write to does not exist, it will be automatically made
Usage:
//getting a FileStream
FileStream stream = File.OpenRead(@"C:\file.txt");

//save it to a new directory
string fileName = stream.Save(@"C:\new_directory\file.txt");
//fileName now equals 'file.txt'

//save it again
string fileName = stream.Save(@"C:\new_directory\file.txt");
//fileName now equals 'file[1].txt' as overwrite defaults to false
//now there are 2 files in that folder: file.txt & file[1].txt

//overwrite the original file
stream.Save(@"C:\new_directory\file.txt", true);

Last edited Dec 6, 2009 at 6:17 AM by naspinski, version 3

Comments

No comments yet.