Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileStream with DeleteOnClose File option

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.

like image 396
Anuraj Avatar asked Sep 18 '09 12:09

Anuraj


People also ask

What is the difference between FileStream and StreamWriter?

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.

What is the difference between StreamWriter StreamReader object and FileStream object?

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.

What does FileStream mean?

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.

How do you create a stream object file?

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.


1 Answers

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.

like image 198
Lasse V. Karlsen Avatar answered Sep 29 '22 23:09

Lasse V. Karlsen