FileStream with DeleteOnClose File option

后端 未结 3 1871
滥情空心
滥情空心 2021-02-08 14:23

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(T         


        
相关标签:
3条回答
  • 2021-02-08 14:31

    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.

    0 讨论(0)
  • 2021-02-08 14:42

    Try including the WriteThrough flag as well in a list using the | operator. See this KB on the requirements for using FILE_FLAG_NO_BUFFERING. Its interesting that MS hasn't included this flag in the enum. Is there a reason why WriteThrough doesn't do what you need in this scenario? You are trying to write secure data?

    0 讨论(0)
  • 2021-02-08 14:45

    Use FileOptions.DeleteOnClose | FILE_FLAG_NO_BUFFERING the & cancels them out.

    FILE_FLAG_NO_BUFFERING & FileOptions.DeleteOnClose returns FileOptions.None

    0 讨论(0)
提交回复
热议问题