CreateFile, FILE_FLAG_BACKUP_SEMANTICS, Directory Management and Handles
<p>I am attempting to grab  a <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365258(v=vs.85).aspx" rel="nofollow">directory handle</a> for the purpose of retrieving a an identifier for the directory. The documentation (linked above) specifies that the <code>FILE_FLAG_BACKUP_SEMANTICS</code> flag needs to be passed to the <code>CreateFile</code> function in order to retrieve the handle, itself. </p>

<p>However, in consulting <a href="http://www.pinvoke.net/default.aspx/kernel32.createfile" rel="nofollow">pinvoke's</a> <code>kernel32.dll</code> signatures, most of the C# candidates look like the following:</p>

<pre><code>    [DllImport("kernell32.dll", SetLastError = true)]
    public static extern SafeFileHandle CreateFile(
        string lpFileName,
        [MarshalAs(UnmanagedType.U4)] FileAccess dwDesiredAccess,
        [MarshalAs(UnmanagedType.U4)] FileShare dwShareMode,
        IntPtr securityAttributes,
        [MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition,
        [MarshalAs(UnmanagedType.U4)] FileAttributes dwFlagsAndAttributes,
        IntPtr hTemplateFile
    );
</code></pre>

<p>The above one-to-one parameter mapping to the C++ <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx" rel="nofollow">CreateFile</a> implies that the <code>dwFlagsAndAttributes</code> parameter is the placeholder for the <code>FILE_FLAG_BACKUP_SEMANTICS</code>; however, the <code>FileAttribute</code> enumeration doesn't appear to have a match for that flag.</p>

<p>Right now (and it's broken) my call looks like:</p>

<pre><code>           var createdFolder =
                FileSystemInteractor.CreateFile(
                    fullPathWithFolderName,
                    FileAccess.Read,
                    FileShare.Read,
                    IntPtr.Zero,
                    FileMode.Open,
                    Kernel32.FILE_FLAG_BACKUP_SEMANTICS,
                    IntPtr.Zero
                );
</code></pre>

<p><code>Kernel32</code> obviously contains the right flag. The compiler error received back is:</p>

<blockquote>
  <p>cannot convert from 'uint' to 'System.IO.FileAttributes'</p>
</blockquote>

<p>The error makes sense; I am just unsure of what massaging of the signature I am able to do because I am new to <code>extern</code> functions. </p>

<p>Is there a <code>FileAttributes</code> that corresponds to the needed flag? Do I need to change the <code>extern</code> signature?</p>