> For the complete documentation index, see [llms.txt](https://www.pinvoke.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pinvoke.dev/kernel32/createfile.md).

# CreateFileW

```csharp
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern unsafe HANDLE CreateFileW(
    PCWSTR lpFileName,
    uint dwDesiredAccess,
    FILE_SHARE_MODE dwShareMode,
    [Optional] SECURITY_ATTRIBUTES* lpSecurityAttributes,
    FILE_CREATION_DISPOSITION dwCreationDisposition,
    FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes,
    HANDLE hTemplateFile);
```

[FILE\_SHARE\_MODE](/filesystem/file_share_mode.md)

[FILE\_CREATION\_DISPOSITION](/filesystem/file_creation_disposition.md)

[FILE\_FLAGS\_AND\_ATTRIBUTES](/filesystem/file_flags_and_attributes.md)
