/// <summary> 在资源管理器中打开某个文件所在的文件夹 </summary> /// <param name="entry">选择要打开的文件</param> /// <param name="isSelected">是否要选中该文件,默认为选中</param> /// <returns>打开成功返回true,否则false</returns> public async Task <bool> LaunchFolderInExplorer(IStorageItem2 entry, bool isSelected = true) { var parentFolder = await entry.GetParentAsync(); var option = new Windows.System.FolderLauncherOptions(); if (isSelected) { option.ItemsToSelect.Add(entry); } return(await Windows.System.Launcher.LaunchFolderAsync(parentFolder, option)); }
/// <summary> /// Recursively determines whether the specified storage item exists in the /// data folder. /// </summary> /// <param name="storageItem">The storage item to check.</param> /// <returns>Whether the item exists in a folder the app controls.</returns> public async Task <bool> PathIsInScopeAsync(IStorageItem2 storageItem) { if (storageItem == null) { return(false); } //if (ProxyFolder.IsEqual(storageItem)) // IsEqual doesn't seem mockable if (ProxyFolder.Path == storageItem.Path) { return(true); } return(await PathIsInScopeAsync( await storageItem.GetParentAsync().AsTask().ConfigureAwait(false) ).ConfigureAwait(false)); }
public async Task <IStorageFolder> GetRootAsync(IStorageFolder folder) { var storageFolder = folder as IStorageItem2; IStorageItem2 parent = null; IStorageItem2 testParent = await storageFolder.GetParentAsync(); while (testParent != null) { testParent = await testParent.GetParentAsync(); if (testParent != null) { parent = testParent; } } return(parent as IStorageFolder); }