I can open file explorer from UWP apps using Launcher.LaunchFolderAsync()
(+), but is there any way to make a file selected in that file explorer window?
There are some ways to achieve this in Win32 apps which involve calling explorer.exe directly and passing parameters to it, which obviously won't work for UWP.
There are two primary ways to access files and folders from your app's data locations: Use ApplicationData properties to retrieve an app data folder. using Windows. Storage; StorageFolder localFolder = ApplicationData.
By default, File Explorer opens to Quick access. If you'd rather have File Explorer open to This PC, go to the View tab and then select Options. In the Open File Explorer to: list, select This PC, and then select Apply.
The picker uses a single, unified interface to let the user pick files and folders from the file system or from other apps. Files picked from other apps are like files from the file system: they are returned as StorageFile objects. In general, your app can operate on them in the same ways as other objects.
UWP app state is stored in the local part of the user profile exclusively.
You can also use the Launcher.LaunchFolderAsync
and use the second parameter FolderLauncherOptions
too.
FolderLauncherOptions
can make the file or folder that you want to select that use the ItemsToSelect
.
ItemsToSelect
is a read-only property, but you can add items to the existing list.
Here's an example, getting a folder using FolderPicker
and then selecting all files:
The first is get the folder:
FolderPicker p = new FolderPicker();
p.FileTypeFilter.Add(".txt");
StorageFolder folder = await p.PickSingleFolderAsync();
And then get all files in the folder
foreach (var temp in await folder.GetFilesAsync())
I can use FolderLauncherOptions to add the item that I want to select.
var t = new FolderLauncherOptions();
foreach (var temp in await folder.GetFilesAsync())
{
t.ItemsToSelect.Add(temp);
}
Then open the file explorer
await Launcher.LaunchFolderAsync(folder, t);
You can see that the explorer will be opened while selecting all files.
You can also add folders to the ItemsToSelect and it will be selected.
See here for more details: https://docs.microsoft.com/en-us/uwp/api/Windows.System.Launcher#Windows_System_Launcher_LaunchFolderAsync_Windows_Storage_IStorageFolder_Windows_System_FolderLauncherOptions_
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With