Filestream

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
 
D

David Browne

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
 
B

Barry Kelly

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top