Sdílet prostřednictvím


StorageFile Class

Definition

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

public ref class StorageFile sealed : IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem2, IStorageItemProperties2, IStorageItemPropertiesWithProvider
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageFile final : IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem2, IStorageItemProperties2, IStorageItemPropertiesWithProvider
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class StorageFile : IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem2, IStorageItemProperties2, IStorageItemPropertiesWithProvider
Public NotInheritable Class StorageFile
Implements IStorageFile, IStorageFile2, IStorageFilePropertiesWithAvailability, IStorageItem2, IStorageItemProperties2, IStorageItemPropertiesWithProvider
Inheritance
Object Platform::Object IInspectable StorageFile
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)
App capabilities
documentsLibrary musicLibrary picturesLibrary videosLibrary

Examples

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
}

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 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.

Version history

Windows version SDK version Value added
2004 19041 GetFileFromPathForUserAsync

Properties

Attributes

Gets the attributes of a file.

ContentType

Gets the MIME type of the contents of the file.

DateCreated

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

DisplayName

Gets a user-friendly name for the file.

DisplayType

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

FileType

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

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

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

Name

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

Path

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

Properties

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

Provider

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

Methods

CopyAndReplaceAsync(IStorageFile)

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

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.

CopyAsync(IStorageFolder, String)

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

CopyAsync(IStorageFolder)

Creates a copy of the file in the specified folder.

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)

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()

Deletes the current file.

DeleteAsync(StorageDeleteOption)

Deletes the current file, optionally deleting the item permanently.

GetBasicPropertiesAsync()

Gets the basic properties of the current file.

GetFileFromApplicationUriAsync(Uri)

Gets a StorageFile object to represent the specified Uniform Resource Identifier (URI) app resource. For examples of sample URIs see Load images and assets tailored for scale, theme, high contrast, and others.

GetFileFromPathAsync(String)

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

GetFileFromPathForUserAsync(User, String)

Gets a StorageFile object based on an absolute path in the file system for a given user.

GetParentAsync()

Gets the parent folder of the current file.

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

GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32)

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

GetScaledImageAsThumbnailAsync(ThumbnailMode)

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

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.

GetThumbnailAsync(ThumbnailMode, UInt32)

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

GetThumbnailAsync(ThumbnailMode)

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

IsEqual(IStorageItem)

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

IsOfType(StorageItemTypes)

Determines whether the current StorageFile matches the specified StorageItemTypes value.

MoveAndReplaceAsync(IStorageFile)

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

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.

MoveAsync(IStorageFolder, String)

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

MoveAsync(IStorageFolder)

Moves the current file to the specified folder.

OpenAsync(FileAccessMode, StorageOpenOptions)

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

OpenAsync(FileAccessMode)

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

OpenReadAsync()

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

OpenSequentialReadAsync()

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

OpenTransactedWriteAsync()

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

OpenTransactedWriteAsync(StorageOpenOptions)

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

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.

RenameAsync(String)

Renames the current file.

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)

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).

Applies to

See also