StorageFile StorageFile StorageFile StorageFile StorageFile Class

Definition

Represents a file. Provides information about the file and its content, and ways to manipulate them.

public : sealed class StorageFile : IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem, IStorageItem2, IStorageItemProperties, IStorageItemProperties2, IStorageItemPropertiesWithProvider, IInputStreamReference, IRandomAccessStreamReference
struct winrt::Windows::Storage::StorageFile : IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem, IStorageItem2, IStorageItemProperties, IStorageItemProperties2, IStorageItemPropertiesWithProvider, IInputStreamReference, IRandomAccessStreamReference
public sealed class StorageFile : IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem, IStorageItem2, IStorageItemProperties, IStorageItemProperties2, IStorageItemPropertiesWithProvider, IInputStreamReference, IRandomAccessStreamReference
Public NotInheritable Class StorageFile Implements IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem, IStorageItem2, IStorageItemProperties, IStorageItemProperties2, IStorageItemPropertiesWithProvider, IInputStreamReference, IRandomAccessStreamReference
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
musicLibrary picturesLibrary videosLibrary documentsLibrary

Examples

This example shows you how to call a file picker, using FileOpenPicker.PickSingleFileAsync to capture and process a file that the users picks.

StorageFile file = await openPicker.PickSingleFileAsync();
// Process picked file
if (file != null)
{
    // Store file for future access
    fileToken = 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.

Remarks

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.

Properties

Attributes Attributes Attributes Attributes Attributes

Gets the attributes of a file.

ContentType ContentType ContentType ContentType ContentType

Gets the MIME type of the contents of the file.

DateCreated DateCreated DateCreated DateCreated DateCreated

Gets the date and time when the current file was created.

DisplayName DisplayName DisplayName DisplayName DisplayName

Gets a user-friendly name for the file.

DisplayType DisplayType DisplayType DisplayType DisplayType

Gets a user-friendly description of the type of the file.

FileType FileType FileType FileType FileType

Gets the type (file name extension) of the file.

FolderRelativeId FolderRelativeId FolderRelativeId FolderRelativeId FolderRelativeId

Gets an identifier for the file. This ID is unique for the query result or StorageFolder that contains the file and can be used to distinguish between items that have the same name.

IsAvailable IsAvailable IsAvailable IsAvailable IsAvailable

Indicates if the file is local, is cached locally, or can be downloaded.

Name Name Name Name Name

Gets the name of the file including the file name extension.

Path Path Path Path Path

Gets the full file-system path of the current file, if the file has a path.

Properties Properties Properties Properties Properties

Gets an object that provides access to the content-related properties of the file.

Provider Provider Provider Provider Provider

Gets the StorageProvider object that contains info about the service that stores the current file.

Methods

CopyAndReplaceAsync(IStorageFile) CopyAndReplaceAsync(IStorageFile) CopyAndReplaceAsync(IStorageFile) CopyAndReplaceAsync(IStorageFile) CopyAndReplaceAsync(IStorageFile)

Replaces the specified file with a copy of the current file.

CopyAsync(IStorageFolder) CopyAsync(IStorageFolder) CopyAsync(IStorageFolder) CopyAsync(IStorageFolder) CopyAsync(IStorageFolder)

Creates a copy of the file in the specified folder.

CopyAsync(IStorageFolder, String) CopyAsync(IStorageFolder, String) CopyAsync(IStorageFolder, String) CopyAsync(IStorageFolder, String) CopyAsync(IStorageFolder, String)

Creates a copy of the file in the specified folder and renames the copy.

CopyAsync(IStorageFolder, String, NameCollisionOption) CopyAsync(IStorageFolder, String, NameCollisionOption) CopyAsync(IStorageFolder, String, NameCollisionOption) CopyAsync(IStorageFolder, String, NameCollisionOption) CopyAsync(IStorageFolder, String, NameCollisionOption)

Creates a copy of the file in the specified folder and renames the copy. This method also specifies what to do if a file with the same name already exists in the destination folder.

CreateStreamedFileAsync(String, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) CreateStreamedFileAsync(String, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) CreateStreamedFileAsync(String, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) CreateStreamedFileAsync(String, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) CreateStreamedFileAsync(String, StreamedFileDataRequestedHandler, IRandomAccessStreamReference)

Creates a StorageFile to represent the specified stream of data. This method lets the app produce the data on-demand by specifying a function to be invoked when the StorageFile that represents the stream is first accessed.

CreateStreamedFileFromUriAsync(String, Uri, IRandomAccessStreamReference) CreateStreamedFileFromUriAsync(String, Uri, IRandomAccessStreamReference) CreateStreamedFileFromUriAsync(String, Uri, IRandomAccessStreamReference) CreateStreamedFileFromUriAsync(String, Uri, IRandomAccessStreamReference) CreateStreamedFileFromUriAsync(String, Uri, IRandomAccessStreamReference)

Creates a StorageFile to represent a stream of data from the specified Uniform Resource Identifier (URI) resource. This method lets the app download the data on-demand when the StorageFile that represents the stream is first accessed.

DeleteAsync() DeleteAsync() DeleteAsync() DeleteAsync() DeleteAsync()

Deletes the current file.

DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption) DeleteAsync(StorageDeleteOption)

Deletes the current file, optionally deleting the item permanently.

GetBasicPropertiesAsync() GetBasicPropertiesAsync() GetBasicPropertiesAsync() GetBasicPropertiesAsync() GetBasicPropertiesAsync()

Gets the basic properties of the current file.

GetFileFromApplicationUriAsync(Uri) GetFileFromApplicationUriAsync(Uri) GetFileFromApplicationUriAsync(Uri) GetFileFromApplicationUriAsync(Uri) GetFileFromApplicationUriAsync(Uri)

Gets a StorageFile object to represent the specified Uniform Resource Identifier (URI) app resource. For examples of sample URIs see How to load file resources.

GetFileFromPathAsync(String) GetFileFromPathAsync(String) GetFileFromPathAsync(String) GetFileFromPathAsync(String) GetFileFromPathAsync(String)

Gets a StorageFile object to represent the file at the specified path.

GetParentAsync() GetParentAsync() GetParentAsync() GetParentAsync() GetParentAsync()

Gets the parent folder of the current file.

GetScaledImageAsThumbnailAsync(ThumbnailMode) GetScaledImageAsThumbnailAsync(ThumbnailMode) GetScaledImageAsThumbnailAsync(ThumbnailMode) GetScaledImageAsThumbnailAsync(ThumbnailMode) GetScaledImageAsThumbnailAsync(ThumbnailMode)

Gets a scaled image as a thumbnail, determined by the purpose of the thumbnail.

GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32)

Gets a scaled image as a thumbnail, determined by the purpose of the thumbnail and the requested size.

GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions)

Gets a scaled image as a thumbnail, determined by the purpose of the thumbnail, the requested size, and the specified options

GetThumbnailAsync(ThumbnailMode) GetThumbnailAsync(ThumbnailMode) GetThumbnailAsync(ThumbnailMode) GetThumbnailAsync(ThumbnailMode) GetThumbnailAsync(ThumbnailMode)

Retrieves an adjusted thumbnail image for the file, determined by the purpose of the thumbnail.

GetThumbnailAsync(ThumbnailMode, UInt32) GetThumbnailAsync(ThumbnailMode, UInt32) GetThumbnailAsync(ThumbnailMode, UInt32) GetThumbnailAsync(ThumbnailMode, UInt32) GetThumbnailAsync(ThumbnailMode, UInt32)

Retrieves an adjusted thumbnail image for the file, determined by the purpose of the thumbnail and the requested size.

GetThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions) GetThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions)

Retrieves an adjusted thumbnail image for the file, determined by the purpose of the thumbnail, the requested size, and the specified options.

IsEqual(IStorageItem) IsEqual(IStorageItem) IsEqual(IStorageItem) IsEqual(IStorageItem) IsEqual(IStorageItem)

Indicates whether the current file is equal to the specified file.

IsOfType(StorageItemTypes) IsOfType(StorageItemTypes) IsOfType(StorageItemTypes) IsOfType(StorageItemTypes) IsOfType(StorageItemTypes)

Determines whether the current StorageFile matches the specified StorageItemTypes value.

MoveAndReplaceAsync(IStorageFile) MoveAndReplaceAsync(IStorageFile) MoveAndReplaceAsync(IStorageFile) MoveAndReplaceAsync(IStorageFile) MoveAndReplaceAsync(IStorageFile)

Moves the current file to the location of the specified file and replaces the specified file in that location.

MoveAsync(IStorageFolder) MoveAsync(IStorageFolder) MoveAsync(IStorageFolder) MoveAsync(IStorageFolder) MoveAsync(IStorageFolder)

Moves the current file to the specified folder.

MoveAsync(IStorageFolder, String) MoveAsync(IStorageFolder, String) MoveAsync(IStorageFolder, String) MoveAsync(IStorageFolder, String) MoveAsync(IStorageFolder, String)

Moves the current file to the specified folder and renames the file according to the desired name.

MoveAsync(IStorageFolder, String, NameCollisionOption) MoveAsync(IStorageFolder, String, NameCollisionOption) MoveAsync(IStorageFolder, String, NameCollisionOption) MoveAsync(IStorageFolder, String, NameCollisionOption) MoveAsync(IStorageFolder, String, NameCollisionOption)

Moves the current file to the specified folder and renames the file according to the desired name. This method also specifies what to do if a file with the same name already exists in the specified folder.

OpenAsync(FileAccessMode) OpenAsync(FileAccessMode) OpenAsync(FileAccessMode) OpenAsync(FileAccessMode) OpenAsync(FileAccessMode)

Opens a random-access stream with the specified options over the specified file.

OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions) OpenAsync(FileAccessMode, StorageOpenOptions)

Opens a random-access stream with the specified options over the specified file.

OpenReadAsync() OpenReadAsync() OpenReadAsync() OpenReadAsync() OpenReadAsync()

Opens a random-access stream over the current file for reading file contents.

OpenSequentialReadAsync() OpenSequentialReadAsync() OpenSequentialReadAsync() OpenSequentialReadAsync() OpenSequentialReadAsync()

Opens a sequential-access stream over the current file for reading file contents.

OpenTransactedWriteAsync() OpenTransactedWriteAsync() OpenTransactedWriteAsync() OpenTransactedWriteAsync() OpenTransactedWriteAsync()

Opens a random-access stream to the file that can be used for transacted-write operations.

OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions) OpenTransactedWriteAsync(StorageOpenOptions)

Opens a random-access stream to the file that can be used for transacted-write operations with the specified options.

RenameAsync(String) RenameAsync(String) RenameAsync(String) RenameAsync(String) RenameAsync(String)

Renames the current file.

RenameAsync(String, NameCollisionOption) RenameAsync(String, NameCollisionOption) RenameAsync(String, NameCollisionOption) RenameAsync(String, NameCollisionOption) RenameAsync(String, NameCollisionOption)

Renames the current file. This method also specifies what to do if an existing item in the current file's location has the same name.

ReplaceWithStreamedFileAsync(IStorageFile, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) ReplaceWithStreamedFileAsync(IStorageFile, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) ReplaceWithStreamedFileAsync(IStorageFile, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) ReplaceWithStreamedFileAsync(IStorageFile, StreamedFileDataRequestedHandler, IRandomAccessStreamReference) ReplaceWithStreamedFileAsync(IStorageFile, StreamedFileDataRequestedHandler, IRandomAccessStreamReference)

Replaces the contents of the file referred to by the specified IStorageFile object with a new data stream. This method lets the app produce the data on-demand by specifying a function to be invoked when the StorageFile that represents the stream is first accessed.

ReplaceWithStreamedFileFromUriAsync(IStorageFile, Uri, IRandomAccessStreamReference) ReplaceWithStreamedFileFromUriAsync(IStorageFile, Uri, IRandomAccessStreamReference) ReplaceWithStreamedFileFromUriAsync(IStorageFile, Uri, IRandomAccessStreamReference) ReplaceWithStreamedFileFromUriAsync(IStorageFile, Uri, IRandomAccessStreamReference) ReplaceWithStreamedFileFromUriAsync(IStorageFile, Uri, IRandomAccessStreamReference)

Replaces the contents of the file referred to by the specified IStorageFile object with a new data stream of the specified Uniform Resource Identifier (URI). This method lets the app download the data on-demand when the StorageFile that represents the stream is first accessed.

The data stream is accessed through the StorageFile that is returned and the data is downloaded on-demand when the StorageFile is first accessed.

Replaces the IStorageFile object that represents the specified file with a new StorageFile that provides a stream of the specified Uniform Resource Identifier (URI).

See Also