Filestream

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Hello

I want to append to a file using Filestream, but is there a way to have
filestream check for the file, and if is's not there, create the file
without having to check for to see if the File exists before hand?

Thanks
J
 
Jason said:
Hello

I want to append to a file using Filestream, but is there a way to have
filestream check for the file, and if is's not there, create the file
without having to check for to see if the File exists before hand?

Something like

using (System.IO.FileStream fs = new FileStream("foo",
FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
fs.Seek(0, SeekOrigin.End);
...
}

David
 
Jason said:
I want to append to a file using Filestream, but is there a way to have
filestream check for the file, and if is's not there, create the file
without having to check for to see if the File exists before hand?

FileMode.Append does that - it creates the file if it doesn't exist.

I.e. 'new FileStream("foo.blah", FileMode.Append, FileAccess.Write)'

-- Barry
 
Back
Top