删除关闭文件 [英] Delete on close files

查看:409
本文介绍了删除关闭文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用语言:C#

理论:
我想创建一个临时文件夹的标志FileOptions.DeleteOnClose的文件。
中的文件创建成功,我写上拿督它,下一步是启动与文件的Process.Start(...)相关的应用程序,并允许用户检查文档,最后我关闭句柄并尽快其他程序关闭句柄到临时文件,该文件是由操作系统删除。

Theory: I want to create a file with the flag FileOptions.DeleteOnClose in a temporary folder. The file is successfully created and I write dato onto it, the next step is to launch the application associated with the file Process.Start(...) and allow the user to inspect the document, finally I close my handle and as soon as other process close the handle to the temporary file, the file is deleted by operating system.

我的问题是其他进程无法打开文件,甚至读书,尽管如果我添加FileShare.ReadWrite | FileShare.Delete到共享模式。

My problem is that other processes cannot open the file, even for reading, despite if I add FileShare.ReadWrite | FileShare.Delete to the sharing mode.

有什么建议?

推荐答案

其他工艺需要指定 FileShare.Delete 当他们打开 DeleteOnClose 文件

The other processes need to specify FileShare.Delete when they open the DeleteOnClose file

MSDN的CreateFile 文档:

FILE_FLAG_DELETE_ON_CLOSE ...该文件的后续打开请求失败,除非 FILE_SHARE_DELETE 指定共享模式。

"FILE_FLAG_DELETE_ON_CLOSE... Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE share mode is specified."

这篇关于删除关闭文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆