檔案、資料夾和媒體櫃Files, folders, and libraries

您可以使用 Windows.StorageWindows.Storage.StreamsWindows.Storage.Pickers 命名空間中的 API,以在檔案中讀取與寫入文字和其他資料格式,以及管理檔案和資料夾。You use the APIs in the Windows.Storage, Windows.Storage.Streams, and Windows.Storage.Pickers namespaces to read and write text and other data formats in files, and to manage files and folders. 在本節中,您也將了解讀取和寫入 app 設定、檔案和資料夾選擇器,並了解特殊的沙箱式位置,例如影片/音樂媒體櫃。In this section, you'll also learn about reading and writing app settings, about file and folder pickers, and about special sand-boxed locations such as the Video/Music library.

主題Topic 描述Description
列舉和查詢檔案和資料夾Enumerate and query files and folders 存取位於資料夾、媒體櫃、裝置或網路位置中的檔案和資料夾。Access files and folders in either a folder, library, device, or network location. 您也可以建構檔案和資料夾查詢,來查詢位置中的檔案和資料夾。You can also query the files and folders in a location by constructing file and folder queries.
建立、寫入和讀取檔案Create, write, and read a file 使用 StorageFile 物件讀取和寫入檔案。Read and write a file using a StorageFile object.
寫入檔案的最佳做法Best practices for writing to files 了解使用 FileIOPathIO 類別的各種檔案寫入方法的最佳做法。Learn best practices for using various file writing methods of the FileIO and PathIO classes.
取得檔案屬性Get file properties 取得由 StorageFile 物件所表示檔案的屬性 (最上層、基本及延伸)。Get properties—top-level, basic, and extended—for a file represented by a StorageFile object.
使用選擇器開啟檔案和資料夾Open files and folders with a picker 讓使用者與選擇器互動以存取檔案和資料夾。Access files and folders by letting the user interact with a picker. 您可以使用 FolderPicker 來存取資料夾。You can use the FolderPicker to gain access to a folder.
使用選擇器儲存檔案Save a file with a picker 使用 FileSavePicker,讓使用者指定想要您的 app 儲存檔案的名稱和位置。Use FileSavePicker to let users specify the name and location where they want your app to save a file.
存取 HomeGroup 內容Accessing HomeGroup content 存取儲存在使用者 HomeGroup 資料夾中的內容,包括圖片、音樂及視訊。Access content stored in the user's HomeGroup folder, including pictures, music, and videos.
判斷 Microsoft OneDrive 檔案的可用性Determining availability of Microsoft OneDrive files 使用 StorageFile.IsAvailable 屬性判斷 Microsoft OneDrive 檔案是否可供使用。Determine if a Microsoft OneDrive file is available using the StorageFile.IsAvailable property.
音樂、圖片及影片媒體櫃中的檔案和資料夾Files and folders in the Music, Pictures, and Videos libraries 將現有的音樂、圖片或影片資料夾新增到對應的媒體櫃中。Add existing folders of music, pictures, or videos to the corresponding libraries. 您也可以從媒體櫃中移除資料夾、取得媒體櫃中的資料夾清單,以及尋找已儲存的相片、音樂和影片。You can also remove folders from libraries, get the list of folders in a library, and discover stored photos, music, and videos.
追蹤最近使用的檔案和資料夾Track recently used files and folders 將使用者經常存取的檔案新增到您應用程式的最近使用清單 (MRU) 中,以追蹤這些檔案。Track files that your user accesses frequently by adding them to your app's most recently used list (MRU). 平台會根據項目上次存取的時間來排序項目,並在達到清單的 25 個項目數限制時移除最舊的項目,為您管理 MRU。The platform manages the MRU for you by sorting items based on when they were last accessed, and by removing the oldest item when the list's 25-item limit is reached. 所有 app 都有自己的 MRU。All apps have their own MRU.
追蹤在背景中的檔案系統變更Track file system changes in the background 追蹤檔案系統變更,即使應用程式未執行時亦然。Track changes to the file system, even when the app isn't running.
存取 SD 記憶卡Access the SD card 您可以在選用的 microSD 記憶卡上儲存和存取非必要的資料,尤其是內部儲存空間有限的低價行動裝置。You can store and access non-essential data on an optional microSD card, especially on low-cost mobile devices that have limited internal storage.
檔案存取權限File access permissions App 預設可以存取特定的檔案系統位置。Apps can access certain file system locations by default. 應用程式也可以透過檔案選擇器或宣告功能,以存取其他位置。Apps can also access additional locations through the file picker, or by declaring capabilities.
快速存取 UWP 中的檔案屬性Fast access to file properties in UWP 有效收集程式庫的檔案和其屬性清單以便用於 UWP 應用程式。Efficiently gather a list of files and their properties from a library to use in a UWP app.

資料夾列舉範例Folder enumeration sample

檔案存取範例File access sample

檔案選擇器範例File picker sample