MSDN Documentation

Windows Runtime APIs

WinRT Storage APIs

The Windows Runtime (WinRT) provides a comprehensive set of APIs for interacting with storage in Windows applications. These APIs enable you to manage files, folders, and local application data in a secure and efficient manner.

Core Concepts

Understanding the fundamental concepts behind WinRT storage is crucial for effective usage:

Key Classes and Interfaces

Here are some of the most important classes and interfaces you'll encounter when working with WinRT storage:

Windows.Storage.StorageFolder

Represents a folder in the file system. You can use this class to:

  • Get a reference to well-known folders (e.g., ApplicationData.Current.LocalFolder).
  • Create new folders within an existing folder.
  • Query for files and subfolders within a folder.
  • Delete folders.

Example:

// Get the local app data folder
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

// Create a new folder
await localFolder.CreateFolderAsync("MyAppData");
View Class Reference

Windows.Storage.StorageFile

Represents a file in the file system. Key operations include:

  • Opening existing files for reading or writing.
  • Creating new files.
  • Copying, moving, and renaming files.
  • Getting file properties like size, date created, and content type.

Example:

// Create a new file
var newFile = await localFolder.CreateFileAsync("settings.txt");

// Write content to the file
await Windows.Storage.FileIO.WriteTextAsync(newFile, "Setting1=Value1\nSetting2=Value2");
View Class Reference

Windows.Storage.FileIO

A static class providing utility methods for reading and writing file content efficiently. It supports various data formats:

  • ReadTextAsync
  • WriteTextAsync
  • ReadBufferAsync
  • WriteBufferAsync
  • ReadLinesAsync
View Class Reference

Windows.Storage.KnownFolders

Provides access to well-known system folders that users typically interact with, such as:

  • KnownFolders.DocumentsLibrary
  • KnownFolders.PicturesLibrary
  • KnownFolders.MusicLibrary
  • KnownFolders.VideosLibrary
  • KnownFolders.RemovableDevices

Permissions: Accessing these libraries often requires specific capabilities declared in your app's manifest.

View Class Reference

Common Scenarios

Explore common tasks and how to implement them using WinRT Storage APIs:

Best Practices