English 中文(简体)
Reset fileOptions.DeleteOnDispose in fileStream possible?
原标题:Reset FileOptions.DeleteOnDispose in FileStream possible?

在文件Stream,我有时使用文件。 删除“分配”特征,如名称所示,在我称之为“处置”方法时,自动删除档案。 如果我在申请期间作出其他决定,我想再次拆除旗帜并保存档案?

由于这是最初的WindowsAPI的特征,我在那里看到,但我无法找到解决办法。

如果有可能,你是否知道如何重新打造国旗?

Thanks Martin

问题回答

我将使用 定期<>处置和处理在<条码>中删除(或不)文档。 我不知道有办法重新确定这一点。

在你创建档案后,不可能更改国旗。 你只能改变档案属性。 我也观看了Windows API,只有暴露的方法是SetFileAttributes,使你只能改变属性。

You should think of different logic to accomplish this, like implement System.IO.File.Delete() by your own when you want file to be deleted and don t relay to FILE_FLAG_DELETE_ON_CLOSE.

样本:

public class FileStreamEx : System.IO.FileStream
{
    private bool _deleteOnDispose = false;

    public FileStreamEx(string path, ....) : base(path, ...) { }

    public bool DeleteOnDispose
    {
        get { return _deleteOnDispose; }
        set { _deleteOnDispose = value; }
    }

    protected override void Dispose(bool disposing)
    {
        if (_deleteOnDispose)
        {
            System.IO.File.Delete(this.Name);
        }

        base.Dispose(disposing);
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签