-api-id | -api-type |
---|---|
T:Windows.Storage.StorageFile |
winrt class |
Represents a file. Provides information about the file and its content, and ways to manipulate them.
Typically, you access StorageFile objects as the result of asynchronous method and/or function calls. For example, both of the static methods GetFileFromPathAsync and GetFileFromApplicationUriAsync return a StorageFile that represents the specified file.
Additionally, whenever you call a file picker to let the user pick a file (or files) the file picker will return the file as a StorageFile.
Note
StorageFile objects can't represent files that are ".lnk", ".url", or ".wsh" file types.
This example shows you how to call a file picker, using FileOpenPicker.PickSingleFileAsync to capture and process a file that the users picks.
var openPicker = new FileOpenPicker();
StorageFile file = await openPicker.PickSingleFileAsync();
// Process picked file
if (file != null)
{
// Store file for future access
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
}
else
{
// The user didn't pick a file
}
openPicker.pickSingleFileAsync().then(function (file) {
if (file) {
// Process picked file
// Store file for future access
var fileToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);
} else {
// The user didn't pick a file
}
});
After PickSingleFileAsync completes, file
gets the picked file as a StorageFile.
In the example, openPicker
contains a FileOpenPicker object. To learn more about using file picker see Open files and folders with a picker.
Additionally, fileToken
gets an identifier that you can use to retrieve the file from the FutureAccessList. To learn more about storing files and folders so you can access them again later, see FutureAccessList, MostRecentlyUsedList and How to track recently used files and folders.
StorageFolder, IStorageFile, IStorageItem, IRandomAccessStreamReference, IInputStreamReference, IStorageItemProperties, IStorageItemProperties2, IStorageItem2, IStorageItemPropertiesWithProvider, IStorageFilePropertiesWithAvailability, Serializing and deserializing data sample, File access sample
documentsLibrary, musicLibrary, picturesLibrary, videosLibrary