Skip to content

Commit ffe6494

Browse files
committed
Add note about elevated desktop apps to pickers
1 parent 11b8a92 commit ffe6494

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

hub/apps/develop/files/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If you're developing packaged WinUI apps, the WinRT storage APIs can be a powerf
4141
| [Create, write, and read a file](/windows/uwp/files/quickstart-reading-and-writing-files) | Read and write a file using a [StorageFile](/uwp/api/Windows.Storage.StorageFile) object. |
4242
| [Best practices for writing to files](/windows/uwp/files/best-practices-for-writing-to-files) | Learn best practices for using various file writing methods of the [FileIO](/uwp/api/windows.storage.fileio) and [PathIO](/uwp/api/windows.storage.pathio) classes. |
4343
| [Get file properties](/windows/uwp/files/quickstart-getting-file-properties) | Get properties—top-level, basic, and extended—for a file represented by a [StorageFile](/uwp/api/Windows.Storage.StorageFile) object. |
44-
| [Open files and folders with a picker](/windows/uwp/files/quickstart-using-file-and-folder-pickers) | Access files and folders by letting the user interact with a picker. You can use the [FolderPicker](/uwp/api/Windows.Storage.Pickers.FolderPicker) to gain access to a folder. |
44+
| [Open files and folders with a picker](/windows/uwp/files/quickstart-using-file-and-folder-pickers) | Access files and folders by letting the user interact with a picker. You can use the [FolderPicker](/uwp/api/Windows.Storage.Pickers.FolderPicker) to gain access to a folder.<br/><br/>**NOTE:** In a desktop app (which includes WinUI 3 apps), you can use file and folder pickers from [Windows.Storage.Pickers](/uwp/api/windows.storage.pickers). However, if the desktop app requires elevation to run, you'll need a different approach because these APIs aren't designed to be used in an elevated app. For an example, see [FileSavePicker](/uwp/api/windows.storage.pickers.filesavepicker#in-a-desktop-app-that-requires-elevation). |
4545
| [Save a file with a picker](/windows/uwp/files/quickstart-save-a-file-with-a-picker) | Use [FileSavePicker](/uwp/api/Windows.Storage.Pickers.FileSavePicker) to let users specify the name and location where they want your app to save a file. |
4646
| [Accessing HomeGroup content](/windows/uwp/files/quickstart-accessing-homegroup-content) | Access content stored in the user's HomeGroup folder, including pictures, music, and videos. |
4747
| [Determining availability of Microsoft OneDrive files](/windows/uwp/files/quickstart-determining-availability-of-microsoft-onedrive-files) | Determine if a Microsoft OneDrive file is available using the [StorageFile.IsAvailable](/uwp/api/windows.storage.storagefile.isavailable) property. |

uwp/files/quickstart-using-file-and-folder-pickers.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ms.assetid: F87DBE2F-77DB-4573-8172-29E11ABEFD34
33
title: Open files and folders with a picker
44
description: Access files and folders by letting the user interact with a picker. You can use the FileOpenPicker and FileSavePicker classes to gain access to files, and the FolderPicker to gain access to a folder.
5-
ms.date: 12/19/2018
5+
ms.date: 02/08/2024
66
ms.topic: article
77
keywords: windows 10, uwp
88
ms.localizationpriority: medium
@@ -11,44 +11,44 @@ ms.localizationpriority: medium
1111

1212
**Important APIs**
1313

14-
- [**FileOpenPicker**](/uwp/api/Windows.Storage.Pickers.FileOpenPicker)
15-
- [**FolderPicker**](/uwp/api/Windows.Storage.Pickers.FolderPicker)
16-
- [**StorageFile**](/uwp/api/Windows.Storage.StorageFile)
14+
- [**FileOpenPicker**](/uwp/api/Windows.Storage.Pickers.FileOpenPicker)
15+
- [**FolderPicker**](/uwp/api/Windows.Storage.Pickers.FolderPicker)
16+
- [**StorageFile**](/uwp/api/Windows.Storage.StorageFile)
1717

1818
Access files and folders by letting the user interact with a picker. You can use the [**FileOpenPicker**](/uwp/api/Windows.Storage.Pickers.FileOpenPicker) and [**FileSavePicker**](/uwp/api/Windows.Storage.Pickers.FileSavePicker) classes to access files, and the [**FolderPicker**](/uwp/api/Windows.Storage.Pickers.FolderPicker) to access a folder.
1919

2020
> [!NOTE]
2121
> For a complete sample, see the [File picker sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/FilePicker).
2222
23-
## Prerequisites
23+
> [!NOTE]
24+
> In a desktop app (which includes WinUI 3 apps), you can use file and folder pickers from [Windows.Storage.Pickers](/uwp/api/windows.storage.pickers). However, if the desktop app requires elevation to run, you'll need a different approach because these APIs aren't designed to be used in an elevated app. For an example, see [FileSavePicker](/uwp/api/windows.storage.pickers.filesavepicker#in-a-desktop-app-that-requires-elevation).
2425
26+
## Prerequisites
2527

26-
- **Understand async programming for Universal Windows Platform (UWP) apps**
28+
- **Understand async programming for Universal Windows Platform (UWP) apps**
2729

2830
You can learn how to write asynchronous apps in C# or Visual Basic, see [Call asynchronous APIs in C# or Visual Basic](../threading-async/call-asynchronous-apis-in-csharp-or-visual-basic.md). To learn how to write asynchronous apps in C++, see [Asynchronous programming in C++](../threading-async/asynchronous-programming-in-cpp-universal-windows-platform-apps.md).
2931

30-
- **Access permissions to the location**
32+
- **Access permissions to the location**
3133

3234
See [File access permissions](file-access-permissions.md).
3335

3436
## File picker UI
3537

36-
3738
A file picker displays information to orient users and provide a consistent experience when opening or saving files.
3839

3940
That information includes:
4041

41-
- The current location
42-
- The item or items that the user picked
43-
- A tree of locations that the user can browse to. These locations include file system locations—such as the Music or Downloads folder—as well as apps that implement the file picker contract (such as Camera, Photos, and Microsoft OneDrive).
42+
- The current location
43+
- The item or items that the user picked
44+
- A tree of locations that the user can browse to. These locations include file system locations—such as the Music or Downloads folder—as well as apps that implement the file picker contract (such as Camera, Photos, and Microsoft OneDrive).
4445

4546
An email app might display a file picker for the user to pick attachments.
4647

4748
![a file picker with two files picked to be opened.](images/picker-multifile-600px.png)
4849

4950
## How pickers work
5051

51-
5252
With a picker your app can access, browse, and save files and folders on the user's system. Your app receives those picks as [**StorageFile**](/uwp/api/Windows.Storage.StorageFile) and [**StorageFolder**](/uwp/api/Windows.Storage.StorageFolder) objects, which you can then operate on.
5353

5454
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**](/uwp/api/Windows.Storage.StorageFile) objects. In general, your app can operate on them in the same ways as other objects. Other apps make files available by participating in file picker contracts. If you want your app to provide files, a save location, or file updates to other apps, see [Integrating with file picker contracts](/previous-versions/windows/apps/hh465192(v=win.10)).
@@ -59,7 +59,6 @@ For example, you might call the file picker in your app so that your user can op
5959

6060
## Pick a single file: complete code listing
6161

62-
6362
```cs
6463
var picker = new Windows.Storage.Pickers.FileOpenPicker();
6564
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
@@ -82,10 +81,9 @@ else
8281

8382
## Pick a single file: step-by-step
8483

85-
8684
Using a file picker involves creating and customizing a file picker object, and then showing the file picker so the user can pick one or more items.
8785

88-
1. **Create and customize a FileOpenPicker**
86+
1. **Create and customize a FileOpenPicker**
8987

9088
```cs
9189
var picker = new Windows.Storage.Pickers.FileOpenPicker();
@@ -95,17 +93,18 @@ Using a file picker involves creating and customizing a file picker object, and
9593
picker.FileTypeFilter.Add(".jpeg");
9694
picker.FileTypeFilter.Add(".png");
9795
```
96+
9897
Set properties on the file picker object relevant to your users and app.
9998

10099
This example creates a rich, visual display of pictures in a convenient location that the user can pick from by setting three properties: [**ViewMode**](/uwp/api/windows.storage.pickers.fileopenpicker.viewmode), [**SuggestedStartLocation**](/uwp/api/windows.storage.pickers.fileopenpicker.suggestedstartlocation), and [**FileTypeFilter**](/uwp/api/windows.storage.pickers.fileopenpicker.filetypefilter).
101100

102-
- Setting [**ViewMode**](/uwp/api/windows.storage.pickers.fileopenpicker.viewmode) to the [**PickerViewMode**](/uwp/api/Windows.Storage.Pickers.PickerViewMode) **Thumbnail** enum value creates a rich, visual display by using picture thumbnails to represent files in the file picker. Do this for picking visual files such as pictures or videos. Otherwise, use [**PickerViewMode.List**](/uwp/api/Windows.Storage.Pickers.PickerViewMode). A hypothetical email app with **Attach Picture or Video** and **Attach Document** features would set the **ViewMode** appropriate to the feature before showing the file picker.
101+
- Setting [**ViewMode**](/uwp/api/windows.storage.pickers.fileopenpicker.viewmode) to the [**PickerViewMode**](/uwp/api/Windows.Storage.Pickers.PickerViewMode) **Thumbnail** enum value creates a rich, visual display by using picture thumbnails to represent files in the file picker. Do this for picking visual files such as pictures or videos. Otherwise, use [**PickerViewMode.List**](/uwp/api/Windows.Storage.Pickers.PickerViewMode). A hypothetical email app with **Attach Picture or Video** and **Attach Document** features would set the **ViewMode** appropriate to the feature before showing the file picker.
103102

104-
- Setting [**SuggestedStartLocation**](/uwp/api/windows.storage.pickers.fileopenpicker.suggestedstartlocation) to Pictures using [**PickerLocationId.PicturesLibrary**](/uwp/api/Windows.Storage.Pickers.PickerLocationId) starts the user in a location where they're likely to find pictures. Set **SuggestedStartLocation** to a location appropriate for the type of file being picked, for example Music, Pictures, Videos, or Documents. From the start location, the user can navigate to other locations.
103+
- Setting [**SuggestedStartLocation**](/uwp/api/windows.storage.pickers.fileopenpicker.suggestedstartlocation) to Pictures using [**PickerLocationId.PicturesLibrary**](/uwp/api/Windows.Storage.Pickers.PickerLocationId) starts the user in a location where they're likely to find pictures. Set **SuggestedStartLocation** to a location appropriate for the type of file being picked, for example Music, Pictures, Videos, or Documents. From the start location, the user can navigate to other locations.
105104

106-
- Using [**FileTypeFilter**](/uwp/api/windows.storage.pickers.fileopenpicker.filetypefilter) to specify file types keeps the user focused on picking files that are relevant. To replace previous file types in the **FileTypeFilter** with new entries, use [**ReplaceAll**](/uwp/api/windows.storage.pickers.fileextensionvector.replaceall) instead of [**Add**](/uwp/api/windows.storage.pickers.fileextensionvector.append).
105+
- Using [**FileTypeFilter**](/uwp/api/windows.storage.pickers.fileopenpicker.filetypefilter) to specify file types keeps the user focused on picking files that are relevant. To replace previous file types in the **FileTypeFilter** with new entries, use [**ReplaceAll**](/uwp/api/windows.storage.pickers.fileextensionvector.replaceall) instead of [**Add**](/uwp/api/windows.storage.pickers.fileextensionvector.append).
107106

108-
2. **Show the FileOpenPicker**
107+
2. **Show the FileOpenPicker**
109108

110109
- **To pick a single file**
111110

@@ -145,7 +144,6 @@ Using a file picker involves creating and customizing a file picker object, and
145144

146145
## Pick a folder: complete code listing
147146

148-
149147
```cs
150148
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
151149
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
@@ -167,4 +165,12 @@ else
167165
```
168166

169167
> [!TIP]
170-
> Whenever your app accesses a file or folder through a picker, add it to your app's [**FutureAccessList**](/uwp/api/windows.storage.accesscache.storageapplicationpermissions.futureaccesslist) or [**MostRecentlyUsedList**](/uwp/api/windows.storage.accesscache.storageapplicationpermissions.mostrecentlyusedlist) to keep track of it. You can learn more about using these lists in [How to track recently-used files and folders](how-to-track-recently-used-files-and-folders.md).
168+
> Whenever your app accesses a file or folder through a picker, add it to your app's [**FutureAccessList**](/uwp/api/windows.storage.accesscache.storageapplicationpermissions.futureaccesslist) or [**MostRecentlyUsedList**](/uwp/api/windows.storage.accesscache.storageapplicationpermissions.mostrecentlyusedlist) to keep track of it. You can learn more about using these lists in [How to track recently-used files and folders](how-to-track-recently-used-files-and-folders.md).
169+
170+
## See also
171+
172+
[Windows.Storage.Pickers](/uwp/api/windows.storage.pickers)
173+
174+
[Files, folders, and libraries](index.md)
175+
176+
[Integrating with file picker contracts](/previous-versions/windows/apps/hh465192(v=win.10))

0 commit comments

Comments
 (0)