StorageFile class

11 out of 30 rated this helpful - Rate this topic

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

Syntax


public sealed class StorageFile : Object,
    IStorageFile,
    IStorageItem,
    IRandomAccessStreamReference,
    IInputStreamReference,
    IStorageItemProperties

Attributes

MarshalingBehaviorAttribute(Agile)
MuseAttribute()
StaticAttribute(Windows.Storage.IStorageFileStatics, NTDDI_WIN8)
VersionAttribute(NTDDI_WIN8)

Members

The StorageFile class has these types of members:

Methods

The StorageFile class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
CopyAndReplaceAsync Replaces the specified file with a copy of the current file.
CopyAsync(IStorageFolder) Creates a copy of the file in the specified folder.
CopyAsync(IStorageFolder, String) Creates a copy of the file in the specified folder, using the desired name.
CopyAsync(IStorageFolder, String, NameCollisionOption) Creates a copy of the file in the specified folder, using the desired name. This method also specifies what to do if an existing file in the specified folder has the same name.
CreateStreamedFileAsync 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 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 Gets a StorageFile object to represent the specified Uniform Resource Identifier (URI) app resource.
GetFileFromPathAsync Gets a StorageFile object to represent the file at the specified path.
GetThumbnailAsync(ThumbnailMode) Retrieves an adjusted thumbnail image for the file, determined by the purpose of the thumbnail.
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) Retrieves an adjusted thumbnail image for the file, determined by the purpose of the thumbnail, the requested size, and the specified options.
IsOfType Determines whether the current StorageFile matches the specified StorageItemTypes value.
MoveAndReplaceAsync Moves the current file to the location of the specified file and replaces the specified file in that location.
MoveAsync(IStorageFolder) Moves the current file to 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, 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 Opens a random-access stream over the 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.
RenameAsync(String) Renames the current file.
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 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 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.

 

Properties

The StorageFile class has these properties.

PropertyAccess typeDescription

Attributes

Read-onlyGets the attributes of a file.

ContentType

Read-onlyGets the MIME type of the contents of the file.

DateCreated

Read-onlyGets the date and time when the current file was created.

DisplayName

Read-onlyGets a user-friendly name for the file.

DisplayType

Read-onlyGets a user-friendly description of the type of the file.

FileType

Read-onlyGets the type (file name extension) of the file.

FolderRelativeId

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

Name

Read-onlyGets the name of the file including the file name extension.

Path

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

Properties

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

 

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.

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
}

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 pickers see FileOpenPicker and Quickstart: Accessing files with file pickers.

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.

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

Capabilities

picturesLibrary
videosLibrary
musicLibrary
documentsLibrary

See also

StorageFolder

 

 

Build date: 2/25/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.