I need to call native Win32 API from .NET code which required file/directory handle. How do I get a handle for the directory?
To get a file handle I use the following code:
using (FileStream stream = File.Open(filePath, FileMode.Open...))
{
var handle = stream.SafeFileHandle;
/// Call Win32 API here
}
- How do I get a handle for a directory?
- Is there any better approach for getting the handle for files? I fill like using FileStream is confusing for those who will read this code.