You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hub/apps/develop/files/winrt-files.md
+84-3Lines changed: 84 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,94 @@ ms.localizationpriority: medium
9
9
---
10
10
# Access files and folders with Windows App SDK and WinRT APIs
11
11
12
-
Packaged Windows App SDK apps can leverage WinRT APIs for reading and writing app settings, file and folder pickers, and special sand-boxed locations such as the Video/Music library. Additionally, any packaged desktop app can utilize both WinRT and Win32 APIs in the Windows SDK, as well as the APIs provided in the .NET SDK. This article provides guidance on how to use the WinRT storage APIs to query files and folders, retrieve file properties, and work with the **Pictures** library.
12
+
Packaged Windows App SDK apps can leverage [WinRT APIs](/uwp/api/) for reading and writing app settings, file and folder pickers, and special sand-boxed locations such as the Video/Music library. Additionally, any packaged desktop app can utilize both WinRT and Win32 APIs in the Windows SDK, as well as the APIs provided in the .NET SDK. This article provides guidance on how to use the WinRT storage APIs to query files and folders, retrieve file properties, and work with the **Pictures** library.
13
13
14
14
## Query files and folders
15
15
16
-
## Get file properties
16
+
The following example shows how to use the [StorageFolder](/uwp/api/windows.storage.storagefolder) and [StorageFile](/uwp/api/windows.storage.storagefile) APIs to query the **Documents** library for files and folders. The example uses the `GetFilesInFolderAsync` method to recursively iterate through the folder structure and append the file names to a `StringBuilder` object.
outputBuilder.AppendLine($"Found {item.Name} in folder {folder.Name}");
43
+
}
44
+
}
45
+
}
46
+
```
47
+
48
+
## Get basic file properties
49
+
50
+
The following example takes the `GetFilesInFolderAsync` method from the previous example and adds the ability to retrieve the file size and date modified for each file. The example uses the [BasicProperties](/uwp/api/windows.storage.fileproperties.basicproperties) API to retrieve the file size and date modified for each file, formats the file size, and appends the size and date modified to the `StringBuilder` object after each file and folder name.
outputBuilder.AppendLine($" - Date modified: {basicProperties.DateModified}");
75
+
}
76
+
}
77
+
}
78
+
```
79
+
80
+
## Working with the Pictures library
81
+
82
+
In this example, the app is configured to receive notifications when the **Pictures** library is updated. The example uses the [StorageLibrary](/uwp/api/windows.storage.storagelibrary) API to retrieve the **Pictures** library and the [DefinitionChanged](/uwp/api/windows.storage.storagelibrary.definitionchanged) event to receive notifications when the library is updated. The `DefinitionChanged` event is invoked when the list of folders in the current library changes. The example uses the library's `Folders` property to iterate through the folders in the **Pictures** library and writes the folder name to the console.
0 commit comments