public static SafeFileHandle CreateSafeFileHandle( this IStorageFolder rootDirectory, string relativePath, FileMode mode, FileAccess access, FileShare share = FileShare.Read, FileOptions options = FileOptions.None) { if (rootDirectory == null) { throw new ArgumentNullException(nameof(rootDirectory)); } if (relativePath == null) { throw new ArgumentNullException(nameof(relativePath)); } HANDLE_CREATION_OPTIONS creationOptions = FileModeToCreationOptions(mode); HANDLE_ACCESS_OPTIONS accessOptions = FileAccessToHandleAccessOptions(access); HANDLE_SHARING_OPTIONS sharingOptions = FileShareToHandleSharingOptions(share); HANDLE_OPTIONS handleOptions = FileOptionsToHandleOptions(options); IStorageFolderHandleAccess handleAccess = rootDirectory.As <IStorageFolderHandleAccess>(); if (handleAccess == null) { return(null); } return(handleAccess.Create( relativePath, creationOptions, accessOptions, sharingOptions, handleOptions, IntPtr.Zero)); }