StorageFile 類別

定義

表示檔案。 提供檔案及其內容的相關資訊,以及操作方式。

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
繼承
Object Platform::Object IInspectable StorageFile
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
應用程式功能
documentsLibrary musicLibrary picturesLibrary videosLibrary

範例

此範例示範如何使用 FileOpenPicker.PickSingleFileAsync 呼叫檔案選擇器,以擷取和處理使用者挑選的檔案。

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
}

PickSingleFileAsync完成之後, file 取得挑選的檔案作為 StorageFile。

在此範例中, openPicker 包含 FileOpenPicker 物件。 若要深入瞭解如何使用檔案選擇器,請參閱 使用選擇器開啟檔案和資料夾

此外, fileToken 取得可用來從 FutureAccessList擷取檔案的識別碼。 若要深入瞭解儲存檔案和資料夾,以便稍後再存取它們,請參閱 FutureAccessListMostRecentlyUsedListTrack 最近使用的檔案和資料夾

備註

一般而言,您會以非同步方法和/或函式呼叫的結果來存取 StorageFile 物件。 例如, GetFileFromPathAsyncGetFileFromApplicationUriAsync 這兩個靜態方法都會傳回代表指定檔案的 StorageFile。

此外,當您呼叫檔案選擇器以讓使用者挑選檔案 (或檔案時,) 檔案選擇器會將檔案傳回為 StorageFile。

注意

StorageFile 物件無法代表 「.lnk」、「.url」 或 「.wsh」 檔案類型的檔案。

版本歷程記錄

Windows 版本 SDK 版本 新增值
2004 19041 GetFileFromPathForUserAsync

屬性

Attributes

取得檔案的屬性。

ContentType

取得檔案內容的 MIME 類型。

DateCreated

取得建立目前檔案的日期和時間。

DisplayName

取得檔案的使用者易記名稱。

DisplayType

取得檔案類型的使用者易記描述。

FileType

取得檔案) (副檔名的類型。

FolderRelativeId

取得檔案的識別碼。 此識別碼對於包含檔案的查詢結果或 StorageFolder 而言是唯一的,而且可用來區別具有相同名稱的專案。

IsAvailable

指出檔案是否為本機、在本機快取,或可下載。

Name

取得檔案名,包括副檔名。

Path

如果檔案有路徑,則取得目前檔案的完整檔案系統路徑。

Properties

取得 物件,這個物件可讓您存取檔案的內容相關屬性。

Provider

取得 StorageProvider 物件,其中包含儲存目前檔案之服務的相關資訊。

方法

CopyAndReplaceAsync(IStorageFile)

以目前檔案的複本取代指定的檔案。

CopyAsync(IStorageFolder)

在指定的資料夾中建立檔案的複本。

CopyAsync(IStorageFolder, String)

在指定的資料夾中建立檔案的複本,並重新命名複本。

CopyAsync(IStorageFolder, String, NameCollisionOption)

在指定的資料夾中建立檔案的複本,並重新命名複本。 如果目的地資料夾中已有相同名稱的檔案,這個方法也會指定該怎麼做。

CreateStreamedFileAsync(String, StreamedFileDataRequestedHandler, IRandomAccessStreamReference)

建立 StorageFile 來表示指定的資料流程。 這個方法可讓應用程式指定第一次存取代表資料流程的 StorageFile 時要叫用的函式,以視需要產生資料。

CreateStreamedFileFromUriAsync(String, Uri, IRandomAccessStreamReference)

建立 StorageFile 來代表來自指定之統一資源識別項 (URI) 資源的資料流程。 當第一次存取代表資料流程的 StorageFile 時,此方法可讓應用程式視需要下載資料。

DeleteAsync()

刪除目前的檔案。

DeleteAsync(StorageDeleteOption)

刪除目前的檔案,選擇性地永久刪除專案。

GetBasicPropertiesAsync()

取得目前檔案的基本屬性。

GetFileFromApplicationUriAsync(Uri)

取得 StorageFile 物件,表示指定的統一資源識別項 (URI) 應用程式資源。 如需範例 URI 的範例,請參閱 載入針對縮放比例、主題、高對比和其他專案量身打造的影像和資產

GetFileFromPathAsync(String)

取得 StorageFile 物件,表示位於指定路徑的檔案。

GetFileFromPathForUserAsync(User, String)

根據指定使用者檔案系統中的絕對路徑取得 StorageFile 物件。

GetParentAsync()

取得目前檔案的父資料夾。

GetScaledImageAsThumbnailAsync(ThumbnailMode)

取得縮放影像做為縮圖,由縮圖的用途決定。

GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32)

取得縮放影像做為縮圖,取決於縮圖的用途和要求的大小。

GetScaledImageAsThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions)

取得縮放影像做為縮圖,由縮圖的用途、要求的大小和指定的選項所決定

GetThumbnailAsync(ThumbnailMode)

擷取檔案的調整縮圖影像,由縮圖的用途決定。

GetThumbnailAsync(ThumbnailMode, UInt32)

擷取檔案的調整縮圖影像,取決於縮圖和要求的大小。

GetThumbnailAsync(ThumbnailMode, UInt32, ThumbnailOptions)

擷取檔案的調整縮圖影像,其用途取決於縮圖、要求的大小和指定的選項。

IsEqual(IStorageItem)

指出目前的檔案是否等於指定的檔案。

IsOfType(StorageItemTypes)

判斷目前的 StorageFile 是否符合指定的 StorageItemTypes 值。

MoveAndReplaceAsync(IStorageFile)

將目前的檔案移至指定檔案的位置,並取代該位置中的指定檔案。

MoveAsync(IStorageFolder)

將目前的檔案移至指定的資料夾。

MoveAsync(IStorageFolder, String)

將目前的檔案移至指定的資料夾,並根據所需的名稱重新命名檔案。

MoveAsync(IStorageFolder, String, NameCollisionOption)

將目前的檔案移至指定的資料夾,並根據所需的名稱重新命名檔案。 如果同名的檔案已存在於指定的資料夾中,這個方法也會指定該怎麼做。

OpenAsync(FileAccessMode)

在指定的檔案上開啟具有指定選項的隨機存取資料流程。

OpenAsync(FileAccessMode, StorageOpenOptions)

在指定的檔案上開啟具有指定選項的隨機存取資料流程。

OpenReadAsync()

開啟目前檔案上的隨機存取資料流程,以讀取檔案內容。

OpenSequentialReadAsync()

開啟目前檔案上的循序存取資料流程,以讀取檔案內容。

OpenTransactedWriteAsync()

開啟可用於交易寫入作業之檔案的隨機存取資料流程。

OpenTransactedWriteAsync(StorageOpenOptions)

開啟檔案的隨機存取資料流程,此資料流程可用於具有指定選項的 Transacted-write 作業。

RenameAsync(String)

重新命名目前的檔案。

RenameAsync(String, NameCollisionOption)

重新命名目前的檔案。 如果目前檔案位置中的現有專案具有相同名稱,這個方法也會指定該怎麼做。

ReplaceWithStreamedFileAsync(IStorageFile, StreamedFileDataRequestedHandler, IRandomAccessStreamReference)

以新的資料流程取代指定 之 IStorageFile 物件所參考之檔案的內容。 這個方法可讓應用程式指定第一次存取代表資料流程的 StorageFile 時要叫用的函式,以視需要產生資料。

ReplaceWithStreamedFileFromUriAsync(IStorageFile, Uri, IRandomAccessStreamReference)

將指定 IStorageFile 物件所參考之檔案的內容取代為指定的統一資源識別項 (URI) 的新資料流程。 當第一次存取代表資料流程的 StorageFile 時,此方法可讓應用程式視需要下載資料。

資料流程是透過傳回的 StorageFile 存取,而且第一次存取 StorageFile 時會隨選下載資料。

將代表指定檔案的 IStorageFile 物件取代為新的 StorageFile ,以提供指定之統一資源識別項的資料流程 (URI) 。

適用於

另請參閱