开心123 发表于 2015-5-21 12:30:57

win8 app 基础知识(FileOpenPicker、FolderPicker、FileSavePicker)

  文件选择对话框 FileOpenPicker
  文件夹选择对话框 FolderPicker
  文件保存对话框 FileSavePicker
  


FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".png");
                StorageFile file = await openPicker.PickSingleFileAsync();
                if (null != file)
                {
                   ...
                }  


FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.List;
                openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                openPicker.FileTypeFilter.Add("*");
                IReadOnlyList files = await openPicker.PickMultipleFilesAsync();
                if (files.Count > 0)
                {
                  // Application now has read/write access to the picked file(s)
                  foreach (StorageFile file in files)
                  {
                        ...
                  }
                }  


FolderPicker folderPicker = new FolderPicker();
                folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                folderPicker.FileTypeFilter.Add(".docx");
                folderPicker.FileTypeFilter.Add(".xlsx");
                folderPicker.FileTypeFilter.Add(".pptx");
                StorageFolder folder = await folderPicker.PickSingleFolderAsync();
                if (null != folder)
                {
                  // Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
                  StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                  ...
                }
  


FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                // Dropdown of file types the user can save the file as
                savePicker.FileTypeChoices.Add("Microsoft Word Document", new List(){".docx", ".doc"});
                savePicker.FileTypeChoices.Add("Plain Text", new List(){".txt"});
                // Default extension if the user does not select a choice explicitly from the dropdown
                savePicker.DefaultFileExtension = ".docx";
                // Default file name if the user does not type one in or select a file to replace
                savePicker.SuggestedFileName = "New Document";
                StorageFile savedItem = await savePicker.PickSaveFileAsync();
                if (null != savedItem)
                {
                     ...
                }  
页: [1]
查看完整版本: win8 app 基础知识(FileOpenPicker、FolderPicker、FileSavePicker)