-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
System.IO.WindowsRuntimeStorageExtensions (from the System.Runtime.WindowsRuntime library) had APIs added for converting from Windows.Storage.IStorageFile and Windows.Storage.IStorageFolder to Microsoft.Win32.SafeHandles.SafeFileHandle. These don't appear to be documented anywhere.
The key usage scenario is taking a WinRT IStorageFile and constructing a System.IO.FileStream around it. This allows synchronous access to IStorageFile/IStorageFolder objects.
The reference definitions:
/runtime/src/libraries/System.Runtime.WindowsRuntime/ref/System.Runtime.WindowsRuntime.cs#L41-L46 [edited to point to dotnet/runtime]:
public static SafeFileHandle CreateSafeFileHandle(
this IStorageFile windowsRuntimeFile,
FileAccess access = FileAccess.ReadWrite,
FileShare share = FileShare.Read,
FileOptions options = FileOptions.None)
public static SafeFileHandle CreateSafeFileHandle(
this IStorageFolder rootDirectory,
string relativePath,
FileMode mode)
public static SafeFileHandle CreateSafeFileHandle(
this IStorageFolder rootDirectory,
string relativePath,
FileMode mode,
FileAccess access,
FileShare share = FileShare.Read,
FileOptions options = FileOptions.None)Arguments work the same as FileStream constructor arguments, with the obvious exception that you can provide a root directory and a relative path.
The API is present in 2.0 releases of System.IO.WindowsRuntime` for .NET 4.6.1, .NET Core 2.0, and Universal Windows Platform 10.0.16299.