In my project I have to create some temp files in an USB device, which I want to delete on Closing. So I used a code like
this.fcommandHandler = new FileStream(TempFileName,
FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.ReadWrite, 512, FileOptions.DeleteOnClose);
It works fine. But the problem is I want to use one more FileOption, like No buffering.
private const FileOptions FILE_FLAG_NO_BUFFERING = (FileOptions)0x20000000;
this.fcommandHandler = new FileStream(TempFileName,
FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.ReadWrite, 512, FileOptions.DeleteOnClose & FILE_FLAG_NO_BUFFERING);
But its not deleting the File after closing. Please help.
Specifically, a FileStream exists to perform reads and writes to the file system. Most streams are pretty low-level in their usage, and deal with data as bytes. A StreamWriter is a wrapper for a Stream that simplifies using that stream to output plain text.
So, the FileStream deals with bytes, where as StreamReader and StreamWriter deals with strings. Points to Remember : Stream is an abstract class for transfering bytes from different sources. It is base class for all other class that reads\writes bytes to different sources.
A FILESTREAM filegroup is a special filegroup that contains file system directories instead of the files themselves. These file system directories are called data containers. Data containers are the interface between Database Engine storage and file system storage.
To manipulate files using FileStream, you need to create an object of FileStream class. This object has four parameters; the Name of the File, FileMode, FileAccess, and FileShare. Name of the file you want to work with along with its extension or the complete path of the file.
You need to use |
instead of &
.
These are binary flags, and when you say &
, you effectively mask them all away, resulting in no options at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With