导出 (0) 打印
全部展开
信息
您所需的主题如下所示。但此主题未包含在此库中。

StorageFile Class

表示文件。提供有关文件及其内容和操作它们的方式的信息。

语法


/* 有关创建或访问此对象的信息,请参阅“备注”。 */

特性

[Muse()]
[Version(0x06020000)]

成员

StorageFile类 具有以下类型的成员:

方法

The StorageFile 类 具有以下方法。 使用 C#、Visual Basic 和 C++,它还可以继承以下内容中的方法 Object 类.

方法描述
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.
GetParentAsync Gets the parent folder of the current file.
GetScaledImageAsThumbnailAsync(ThumbnailMode) Gets a scaled image as a thumbnail, determined by the purpose of the thumbnail.
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) Gets a scaled image as a thumbnail, determined by the purpose of the thumbnail, the requested size, and the specified options
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.
IsEqual Indicates whether the current file is equal to the specified file.
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.

 

属性

StorageFile类 具有以下属性。

属性访问类型描述

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.

 

备注

通常,可以访问 StorageFile 对象作为异步方法和/否函数调用的结果。例如,静态方法 GetFileFromPathAsyncGetFileFromApplicationUriAsync 都返回表示指定文件的 StorageFile

此外,无论何时您调用文件选择器以让用户选择一个文件(或多个文件),文件选择器都会将文件作为 StorageFile 返回。

注意  StorageFile 对象不能表示文件类型为 ".lnk"、".url" 或 ".wsh" 的文件。

示例

此示例演示如何调用文件选择器,使用 FileOpenPicker.PickSingleFileAsync 来捕获并处理用户选择的文件。



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
   }
});

PickSingleFileAsync 完成后,file 将选择的文件获取为 StorageFile

在此示例中,openPicker 包含一个 FileOpenPicker 对象。要了解关于使用文件选择器的详细信息,请参见 FileOpenPicker快速入门:使用文件选择器访问文件

此外,fileToken 会获取您可以用于从 FutureAccessList 检索文件的标识符。要了解关于存储文件和文件夹以便您可以稍后继续访问的详细信息,请参见 FutureAccessListMostRecentlyUsedList如何跟踪最近使用的文件和文件夹

要求

最低受支持的客户端

Windows 8 [仅 Windows 应用商店应用]

最低受支持的服务器

Windows Server 2012 [仅 Windows 应用商店应用]

最低受支持的电话

Windows Phone 8

命名空间

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

元数据

Windows.winmd

Capabilities

picturesLibrary
videosLibrary
musicLibrary
documentsLibrary

另请参阅

StorageFolder
IStorageFile
IStorageItem
IRandomAccessStreamReference
IInputStreamReference
IStorageItemProperties
IStorageItemProperties2
IStorageItem2
IStorageItemPropertiesWithProvider
IStorageFilePropertiesWithAvailability

 

 

Microsoft 正在进行一项网上调查,以了解您对 MSDN 网站的意见。 如果您选择参加,我们将会在您离开 MSDN 网站时向您显示该网上调查。

是否要参加?
显示:
© 2015 Microsoft