// 选择一个本地文件 private async void btnPickLocalFile_Click(object sender, RoutedEventArgs e) { StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\hololens.jpg"); if (_fileOpenPickerUI.CanAddFile(file)) { AddFileResult result = _fileOpenPickerUI.AddFile("myFile", file); lblMsg.Text = "选择的文件: " + file.Name; lblMsg.Text += Environment.NewLine; lblMsg.Text += "AddFileResult: " + result.ToString(); } }
private async void AddFileButton_Click(object sender, RoutedEventArgs e) { StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(@"CachedFile.txt", CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(file, @"Cached file created..."); CachedFileUpdater.SetUpdateInformation(file, "CachedFile", ReadActivationMode.BeforeAccess, WriteActivationMode.NotNeeded, CachedFileOptions.RequireUpdateOnAccess); bool inBasket; switch (fileOpenPickerUI.AddFile(id, file)) { case AddFileResult.Added: case AddFileResult.AlreadyAdded: inBasket = true; OutputTextBlock.Text = Status.FileAdded; break; default: inBasket = false; OutputTextBlock.Text = Status.FileAddFailed; break; } UpdateButtonState(inBasket); }
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems != null) { var addedStickers = e.AddedItems.OfType <Sticker>(); foreach (var item in addedStickers) { if (_pickerUi.CanAddFile(item.File)) { _pickerUi.AddFile(item.File.Path, item.File); } } } if (e.RemovedItems != null) { var removedItems = e.RemovedItems.OfType <Sticker>(); foreach (var item in removedItems) { if (_pickerUi.ContainsFile(item.File.Path)) { _pickerUi.RemoveFile(item.File.Path); } } } }
public async Task Add(PickedFile file) { IStorageFile f = null; if (file.Source == PickedFileSource.Local) { f = await StorageFile.GetFileFromPathAsync(file.Path); } else if (file.Source == PickedFileSource.Uri) { var uri = new Uri(file.Path); f = await StorageFile.CreateStreamedFileFromUriAsync(Path.GetFileName(file.Path), uri, RandomAccessStreamReference.CreateFromUri(uri)); } else { throw new ArgumentException("Unknown File source.", nameof(f)); } lock (syncObject) { if (fileOpenPickerUI.CanAddFile(f)) { fileOpenPickerUI.AddFile(file.Path, f); } } }
// 本 CachedFile 用于从 Local 更新(由 CachedFileUpdater 更新 CachedFile) private async void btnPickCachedFileLocal_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(@"webabcdCachedFileUpdaterLocal.txt", CreationCollisionOption.ReplaceExisting); string textContent = "I am webabcd"; await FileIO.WriteTextAsync(file, textContent); /* * 设置 CachedFile,即将文件关联到 CachedFileUpdater * SetUpdateInformation(IStorageFile file, string contentId, ReadActivationMode readMode, WriteActivationMode writeMode, CachedFileOptions options); * file - 与 CachedFileUpdater 关联的文件 * contentId - 与 CachedFileUpdater 关联的文件标识 */ CachedFileUpdater.SetUpdateInformation(file, "cachedFileLocal", ReadActivationMode.BeforeAccess, WriteActivationMode.NotNeeded, CachedFileOptions.RequireUpdateOnAccess); lblMsg.Text = "选择的文件: " + file.Name; AddFileResult result = _fileOpenPickerUI.AddFile("myFile", file); }
public async Task ShowRecordings() { var recordings = await RecordingStorage.GetRecordings(); RecordingList.ItemsSource = recordings .Select(t => new RecordingViewModel(t.Item1, () => { if (!_pickerUi.ContainsFile(t.Item1)) { _pickerUi.AddFile(t.Item1, t.Item2); } else { _pickerUi.RemoveFile(t.Item1); } })) .ToArray(); }
/// <summary> /// Invoked when the selected collection of files changes. /// </summary> /// <param name="sender">The GridView instance used to display the available files.</param> /// <param name="e">Event data that describes how the selection changed.</param> private void HandleSelectedFileChanged(Object sender, SelectionChangedEventArgs e) { // Update the picker 'basket' with the newly selected items foreach (var addedFile in e.AddedItems.Cast <FileInfo>()) { if (_fileOpenPickerUI.CanAddFile(addedFile.File)) { _fileOpenPickerUI.AddFile(addedFile.Title, addedFile.File); } } // Update the picker 'basket' to remove any newly removed items foreach (var removedFile in e.RemovedItems.Cast <FileInfo>()) { if (_fileOpenPickerUI.ContainsFile(removedFile.Title)) { _fileOpenPickerUI.RemoveFile(removedFile.Title); } } }
private async void AddLocalFileButton_Click(object sender, RoutedEventArgs e) { StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\squareTile-sdk.png"); bool inBasket; switch (fileOpenPickerUI.AddFile(id, file)) { case AddFileResult.Added: case AddFileResult.AlreadyAdded: inBasket = true; OutputTextBlock.Text = Status.FileAdded; break; default: inBasket = false; OutputTextBlock.Text = Status.FileAddFailed; break; } UpdateButtonState(inBasket); }
private async void AddLocalFileButton_Click(object sender, RoutedEventArgs e) { StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\squareTile-sdk.png"); bool inBasket; switch (fileOpenPickerUI.AddFile(id, file)) { case AddFileResult.Added: case AddFileResult.AlreadyAdded: inBasket = true; await new Windows.UI.Popups.MessageDialog("File added to the basket.").ShowAsync(); break; default: inBasket = false; await new Windows.UI.Popups.MessageDialog("Couldn't add file to the basket.").ShowAsync(); break; } UpdateButtonState(inBasket); }
private async void AddUriFileButton_Click(object sender, RoutedEventArgs e) { const string filename = @"URI.png"; // This will be used as the filename of the StorageFile object that references the specified URI FileOpenPickerPage.Current.NotifyUser("", NotifyType.StatusMessage); Uri uri = null; try { uri = new Uri(URLInput.Text); } catch (FormatException) { FileOpenPickerPage.Current.NotifyUser("Please enter a valid URL.", NotifyType.ErrorMessage); } if (uri != null) { StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(filename, uri, RandomAccessStreamReference.CreateFromUri(uri)); bool inBasket; switch (fileOpenPickerUI.AddFile(id, file)) { case AddFileResult.Added: case AddFileResult.AlreadyAdded: inBasket = true; OutputTextBlock.Text = Status.FileAdded; break; default: inBasket = false; OutputTextBlock.Text = Status.FileAddFailed; break; } UpdateButtonState(inBasket); } }
async private void ResumeListSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!_saving) { var grid_view = sender as ListView; var resume = grid_view.SelectedItem as Resume; var resume_file = resume?.GetFile(); if (resume_file != null) { if (_previous_id != null) { _open_basket.RemoveFile(_previous_id); } _open_basket.AddFile(resume.ResumeID, resume_file); _open_basket.Title = $"{resume.Name} selected"; _previous_id = resume.ResumeID; } else { await new MessageDialog("Resume is null").ShowAsync(); } } }
public AddFileResult AddFile(string id, IStorageFile file) { return(_fileOpenPicker.AddFile(id, file)); }