private async Task <bool> LaunchFilePickerAndExportAsync() { bool processIsSuccessful = false; FileSavePicker savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.Downloads, SuggestedFileName = "PhiliaContacts" }; savePicker.FileTypeChoices.Add("Virtual Contact File", new List <string>() { ".vcf" }); StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { try { IsBusy = true; CachedFileManager.DeferUpdates(file); await FileIO.WriteTextAsync(file, Writer.Write(Manager)); Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); processIsSuccessful = status == Windows.Storage.Provider.FileUpdateStatus.Complete; if (processIsSuccessful) { if (WorkflowSuccessAction != null) { WorkflowSuccessAction.Invoke(); } } else { if (WorkflowFailureAction != null) { WorkflowFailureAction.Invoke(); } } } finally { DispatcherHelper.CheckBeginInvokeOnUI(() => { IsBusy = false; ExportCommand.RaiseCanExecuteChanged(); }); } } return(processIsSuccessful); }
private async void SaveButton(object sender, RoutedEventArgs e) { if (File == null) { Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; if (AppVar.FileTypeEdit == FileTypes.HtmlFile) { savePicker.FileTypeChoices.Add("HTML file", new List <string>() { ".html" }); } else { savePicker.FileTypeChoices.Add("Text file", new List <string>() { ".txt" }); } savePicker.SuggestedFileName = AppVar.FileNameEdit; Windows.Storage.StorageFile File = await savePicker.PickSaveFileAsync(); if (File != null) { Windows.Storage.CachedFileManager.DeferUpdates(File); Windows.Storage.Streams.IRandomAccessStream randAccStream = await File.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); editor.Document.SaveToStream(Windows.UI.Text.TextGetOptions.None, randAccStream); // Let Windows know that we're finished changing the file so the // other app can update the remote version of the file. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(File); if (status != Windows.Storage.Provider.FileUpdateStatus.Complete) { Windows.UI.Popups.MessageDialog errorBox = new Windows.UI.Popups.MessageDialog("File " + File.Name + " couldn't be saved."); await errorBox.ShowAsync(); } else { AppTitle.Text = File.Name; } } } else { editor.Document.GetText(TextGetOptions.None, out string docText); await Windows.Storage.FileIO.WriteTextAsync(File, docText); } }
private async void ExportButton_Click(object sender, RoutedEventArgs e) { if (IsAdmin()) { var activeDB = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("SamplesDB.db"); var buffer = await Windows.Storage.FileIO.ReadBufferAsync(activeDB); var savePicker = new Windows.Storage.Pickers.FileSavePicker { SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder }; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("SQLite Database", new List <string>() { ".db" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "SamplesDB"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file //await Windows.Storage.FileIO.WriteTextAsync(file, file.Name); await Windows.Storage.FileIO.WriteBufferAsync(file, buffer); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { ExportSuccess.Text = "File " + file.Name + " was exported."; } else { ExportSuccess.Text = "File " + file.Name + " couldn't be exported."; } } else { ExportSuccess.Text = "Operation cancelled or interrupted."; } ExportSuccess.Visibility = Visibility.Visible; } else { PrivilegeError(); } }
private async void Newprjbtn_Click(object sender, RoutedEventArgs e) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Micro_Wizard Project", new List <string>() { ".mcpr" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "Micro_prj"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file await Windows.Storage.FileIO.WriteTextAsync(file, "chip_select : " + mcubrandcombo.SelectedItem.ToString() + " -> " + mcumodelcombo.SelectedItem.ToString() + " -> " + mcusubmodelcombo.SelectedItem.ToString() + "\r\n"); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { //this.textBlock.Text = "File " + file.Name + " was saved."; } else { //this.textBlock.Text = "File " + file.Name + " couldn't be saved."; } } else { //this.textBlock.Text = "Operation cancelled."; } shared_var.project_line = await Windows.Storage.FileIO.ReadTextAsync(file); if (shared_var.project_line.Contains("chip_select : ARM -> ST -> stm32f103c8\r\n")) { mainframe.Navigate(typeof(Home_stm32f103)); } else { DisplayunsopportedprjtDialog(); } }
private async void Save_Click(object sender, RoutedEventArgs e) { if (current_file != null) { await Windows.Storage.FileIO.WriteTextAsync(current_file, Editor.Text); Htto.Tools.showInformation(current_file.Name, "保存成功"); } else if (current_file == null) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("merdog program", new List <string>() { ".mer" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "new"; current_file = await savePicker.PickSaveFileAsync(); if (current_file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(current_file); // write to file await Windows.Storage.FileIO.WriteTextAsync(current_file, Editor.Text); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(current_file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { Htto.Tools.showInformation(current_file.Name, "保存文件成功"); } else { Htto.Tools.showInformation(current_file.Name, "保存文件失败"); } } else { Htto.Tools.showInformation("信息", "保存文件取消"); } } if (current_file != null) { SFileName.Text = current_file.Name; } }
private async void BtnSave_Click(object sender, RoutedEventArgs e) { InkStrokeContainer container = new InkStrokeContainer(); foreach (var item in _inkStrokes) { container.AddStrokes(from stroke in item.GetStrokes() select stroke.Clone()); } if (container.GetStrokes().Count > 0) { Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("GIF with embedded ISF", new List <string>() { ".gif" }); savePicker.DefaultFileExtension = ".gif"; savePicker.SuggestedFileName = "PaperPencilPen001"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); using (IOutputStream outputStream = stream.GetOutputStreamAt(0)) { await container.SaveAsync(outputStream); await outputStream.FlushAsync(); } stream.Dispose(); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { //file saved } else { //not saved } } else { //cancelled } } }
private async Task SaveToFileAsync(string content) { var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, }; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Galileo", new List <string>() { ".dft" }); savePicker.FileTypeChoices.Add("JSON Document", new List <string>() { ".json" }); savePicker.FileTypeChoices.Add("Text Document", new List <string>() { ".txt" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = Project.Title; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file await Windows.Storage.FileIO.WriteTextAsync(file, content); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); FileInfo fileInfo = new FileInfo(file.Path); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { // File saved NotificationService.FileSavedNotification(fileInfo); } else { // File couldn't be saved NotificationService.FileNotSavedNotification(fileInfo); } } else { // Operation cancelled. } }
private async void createMapping(object sender, RoutedEventArgs e) { tf.refreshLetters(); mf = new MapFile(tf); textBlock3.Text = "Creating the mapping for passwords..."; disableAllControls(); try { await Task.Run(() => createMap()); } catch (Exception) { await new MessageDialog("Increase the number of allocated entries in settings to eliminate a security threat.", "Mapping file does not contain enough characters not to create any duplicates.").ShowAsync(); enableAllControls(); textBlock3.Text = ""; return; } enableAllControls(); textBlock3.Text = ""; var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("Text File (.txt)", new List <string>() { ".txt" }); savePicker.SuggestedFileName = "Not a Passwords Text File"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); await Windows.Storage.FileIO.WriteTextAsync(file, mf.getFileText()); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { await new MessageDialog("", "File saved sucessfully.").ShowAsync(); } else { await new MessageDialog("", "Failed to save file.").ShowAsync(); } } }
private async void CommentSave_Click(object sender, RoutedEventArgs e) { //Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); //savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; //// Dropdown of file types the user can save the file as //savePicker.FileTypeChoices.Add("Rich Text", new List<string>() { ".rtf" }); //// Default file name if the user does not type one in or select a file to replace //savePicker.SuggestedFileName = "New Document"; //Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); Windows.Storage.StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; //StorageFile file; //if (await folder.GetFileAsync(viewmodel.SelectedVideo.Name + ".rtf") != null) //{ // file = await folder.GetFileAsync(viewmodel.SelectedVideo.Name + ".rtf"); //} //else //{ // file = await folder.CreateFileAsync(viewmodel.SelectedVideo.Name + ".rtf"); //} StorageFile file = await folder.CreateFileAsync(viewmodel.SelectedVideo.Name + ".rtf", CreationCollisionOption.ReplaceExisting); if (file != null) { //using (var filestream = await file.OpenAsync(FileAccessMode.ReadWrite)) //{ // await RandomAccessStream.CopyAsync(imageStream, filestream); //} // Prevent updates to the remote version of the file until we // finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file using (Windows.Storage.Streams.IRandomAccessStream randAccStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite)) { EditZone.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream); } // Let Windows know that we're finished changing the file so the // other app can update the remote version of the file. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status != Windows.Storage.Provider.FileUpdateStatus.Complete) { Windows.UI.Popups.MessageDialog errorBox = new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved."); await errorBox.ShowAsync(); } viewmodel.SelectedVideo.NotePath = viewmodel.SelectedVideo.Name + ".rtf"; } }
private async void SaveStrokes(StorageFolder storageFolder, List <InkStrokeContainer> _strokes) { // Remove existing files from storageFolder if (storageFolder != null) { IReadOnlyList <StorageFile> files = await storageFolder.GetFilesAsync(); foreach (var f in files) { if (f.FileType.Equals(".gif") && f.DisplayName.StartsWith("InkStroke")) { await f.DeleteAsync(); } } } // Get all strokes on the InkCanvas. IReadOnlyList <InkStroke> currentStrokes; int i = 0; foreach (var item in _strokes) { if (item.GetStrokes().Count > 0) { // Strokes present on ink canvas. currentStrokes = item.GetStrokes(); var file = await storageFolder.CreateFileAsync("InkStroke" + i.ToString() + ".gif", CreationCollisionOption.ReplaceExisting); // When chosen, picker returns a reference to the selected file. if (file != null) { // Prevent updates to the file until updates are finalized with call to CompleteUpdatesAsync. CachedFileManager.DeferUpdates(file); // Open a file stream for writing. IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite); // Write the ink strokes to the output stream. using (IOutputStream outputStream = stream.GetOutputStreamAt(0)) { await item.SaveAsync(outputStream); await outputStream.FlushAsync(); } stream.Dispose(); // Finalize write so other apps can update file. Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); } i++; } } ShowFlyoutAboveInkToolbar?.Invoke("Project Saved"); }
/*public async Task<FileSaveResult> SaveImageAsync(string path, byte[] image, object nativeRepresentation = null) * { * try * { * StorageFile storageFile; * if (string.IsNullOrEmpty(path)) * { * storageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(Forms.StaticVariables.DefaultCarrierImageSaveName, CreationCollisionOption.ReplaceExisting); * } * else * { * storageFile = (StorageFile)nativeRepresentation; * } * await Windows.Storage.FileIO.WriteBytesAsync(storageFile, image); * * return new FileSaveResult() { SaveLocation = storageFile.Path }; * //return (true, $"Image saved to {storageFile.Path}."); * } * catch(Exception ex) * { * return new FileSaveResult() { ErrorMessage = ex.Message }; * } * }*/ // https://docs.microsoft.com/en-us/windows/uwp/files/quickstart-save-a-file-with-a-picker public async Task <FileSaveResult> SaveFileAsync(string fileName, byte[] fileBytes) { try { FileSavePicker savePicker = new FileSavePicker() { SuggestedStartLocation = PickerLocationId.Desktop, }; var ext = Path.GetExtension(fileName); savePicker.FileTypeChoices.Add("File", new List <string>() { ext }); savePicker.SuggestedFileName = fileName; StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. CachedFileManager.DeferUpdates(file); // write to file await Windows.Storage.FileIO.WriteBytesAsync(file, fileBytes); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); if (status != Windows.Storage.Provider.FileUpdateStatus.Complete) { return(new FileSaveResult() { ErrorMessage = "The file couldn't be saved (FileUpdateStatus not complete)." }); } } } catch (Exception ex) { return(new FileSaveResult() { ErrorMessage = ex.Message }); } return(new FileSaveResult() { ErrorMessage = null }); }
private async void buttonSave_ClickAsync(object sender, RoutedEventArgs e) { // // Get all strokes on the InkCanvas. IReadOnlyList <InkStroke> currentStrokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes(); if (currentStrokes.Count > 0) { // Use a file picker to identify ink file. Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add( "GIF with embedded ISF", new List <string>() { ".gif" }); savePicker.DefaultFileExtension = ".gif"; savePicker.SuggestedFileName = "InkSample"; // Show the file picker. Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); // When selected, picker returns a reference to the file. if (file != null) { // Prevent updates to the file until updates are // finalized with call to CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // Open a file stream for writing. IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); // Write the ink strokes to the output stream. using (IOutputStream outputStream = stream.GetOutputStreamAt(0)) { await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream); await outputStream.FlushAsync(); } stream.Dispose(); // Finalize write so other apps can update file. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { // File saved. } } } }
private async void saveGIF(InkStrokeContainer strokeContainer) { var strokes = strokeContainer.GetStrokes(); if (strokes.Count > 0) { Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop; savePicker.FileTypeChoices.Add( "Obrazek", new List <string>() { ".gif" }); savePicker.DefaultFileExtension = ".gif"; savePicker.SuggestedFileName = "Nowy gif"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); // When chosen, picker returns a reference to the selected file. if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); using (IOutputStream outputStream = stream.GetOutputStreamAt(0)) { await strokeContainer.SaveAsync(outputStream); await outputStream.FlushAsync(); } stream.Dispose(); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { Debug.WriteLine("File " + file.Name + " was saved."); } else { Debug.WriteLine("File " + file.Name + " was NOT saved."); } } else { Debug.WriteLine("Cancelled"); } } }
// private async Task SaveAFile(string txt) // { // bool usedPicker = true; // FileSavePicker savePicker = null; // Windows.Storage.StorageFile file = null; //#if IoTCore //#else // savePicker = new Windows.Storage.Pickers.FileSavePicker(); //#endif // if (savePicker != null) // { // savePicker.SuggestedStartLocation = // Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // // Dropdown of file types the user can save the file as // savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" }); // // Default file name if the user does not type one in or select a file to replace // savePicker.SuggestedFileName = "New Document"; // file = await savePicker.PickSaveFileAsync(); // if (file == null) // { // PostMessage("SaveAFile", "Operation cancelled."); // rcvr = null; // return; // } // } // FileDetail rcvFile = await rcvr.ReadAsync(); // if (rcvFile == null) // { // PostMessage("SaveAFile", "Operation failed."); // rcvr = null; // return; // } // if (savePicker != null) // { // await file.RenameAsync(rcvFile.filename); // } // else // { // usedPicker = false; // Windows.Storage.StorageFolder storageFolder = // Windows.Storage.ApplicationData.Current.LocalFolder; // file = // await storageFolder.CreateFileAsync(rcvFile.filename, // Windows.Storage.CreationCollisionOption.ReplaceExisting); // } // if (file != null) // { // // Prevent updates to the remote version of the file until // // we finish making changes and call CompleteUpdatesAsync. // Windows.Storage.CachedFileManager.DeferUpdates(file); // // write to file // await Windows.Storage.FileIO.WriteTextAsync(file, rcvFile.txt); // // Let Windows know that we're finished changing the file so // // the other app can update the remote version of the file. // // Completing updates may require Windows to ask for user input. // Windows.Storage.Provider.FileUpdateStatus status = // await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); // if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) // { // PostMessage( "File " , file.Name + " was saved in \r\n" + file.Path); // } // else // { // PostMessage( "File " , file.Name + " couldn't be saved."); // } // } // rcvr = null; // } private async Task SaveAFile2(FileDetail rcvFile) { FileSavePicker savePicker = null; Windows.Storage.StorageFile file = null; savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Plain Text", new List <string>() { ".txt" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = rcvFile.filename; file = await savePicker.PickSaveFileAsync(); if (file == null) { PostMessage("SaveAFile", "Operation cancelled."); return; } //await file.RenameAsync(rcvFile.filename); // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file await Windows.Storage.FileIO.WriteTextAsync(file, rcvFile.txt); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { PostMessage("File ", file.Name + " was saved in \r\n" + file.Path); } else { PostMessage("File ", file.Name + " couldn't be saved."); } }
/// Save coloring image source, ink, and inked image to local folder. private async void Save_Click(object sender, RoutedEventArgs e) { // Find exisiting folder, or create new folder. StorageFolder folder = null; if (_Foldername == null) { try { folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(Constants.inkImageFolder, CreationCollisionOption.GenerateUniqueName); _Foldername = folder.Name; // Save coloring image source. StorageFile imgsrcfile = await folder.CreateFileAsync(Constants.imgsrcFile); await FileIO.WriteTextAsync(imgsrcfile, _Imgsrc); } catch (Exception ex) { Debug.WriteLine(ex); } } else { folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(_Foldername); } // Save ink. StorageFile myInkFile = await folder.CreateFileAsync(Constants.inkFile, CreationCollisionOption.ReplaceExisting); IReadOnlyList <InkStroke> currentStrokes = myInkCanvas.InkPresenter.StrokeContainer.GetStrokes(); if (myInkFile != null && currentStrokes.Count > 0) { Windows.Storage.CachedFileManager.DeferUpdates(myInkFile); IRandomAccessStream stream = await myInkFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); using (IOutputStream outputStream = stream.GetOutputStreamAt(0)) { await myInkCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream); await outputStream.FlushAsync(); } stream.Dispose(); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(myInkFile); } // Save inked image. StorageFile myInkedImageFile = await folder.CreateFileAsync(Constants.inkedImageFile, CreationCollisionOption.ReplaceExisting); await Save_InkedImagetoFile(myInkedImageFile); }
/// <summary> /// 将变更覆盖原有文件。 /// </summary> /// <returns></returns> private async Task SaveOrginalFileAsync() { CachedFileManager.DeferUpdates(_file); await FileIO.WriteLinesAsync(_file, _model.ToStringArray()); Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(_file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { Debug.WriteLine("File " + _file.Name + " was saved."); } else { throw new FileNotSaveException($"File {_file.Name} couldn't be saved."); } DrawRectangleColor(_model?.GroupDateTimesByTotal(), true); }
private async void SaveMoiNewRekv_Click(object sender, RoutedEventArgs e) { var savePicker5 = new Windows.Storage.Pickers.FileSavePicker(); savePicker5.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Поле выбора типа файла в диалоге savePicker5.FileTypeChoices.Add("Документ", new List <string>() { ".mrekv" }); // Default file name if the user does not type one in or select a file to replace savePicker5.SuggestedFileName = "Реквизиты моей организации"; // Windows.Storage.StorageFile Myfile5 = await savePicker5.PickSaveFileAsync(); if (Myfile5 != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(Myfile5); // write to file //await Windows.Storage.FileIO.WriteTextAsync(file, file.Name); //запись в файл имени string TShapka = ""; if (CHeckBoxSchapka5.IsChecked == true) { TShapka = "1"; } await FileIO.WriteTextAsync(Myfile5, TextBoxMoeNaimenovaniePolnoe5.Text + ";" + TextBoxMoeNaimenovanieSokr5.Text + ";" + TextBoxMojINN5.Text + ";" + TextBoxMojKPP5.Text + ";" + TextBoxMojOGRN5.Text + ";" + TextBoxMoiBankName5.Text + ";" + TextBoxMoiBankBIK5.Text + ";" + TextBoxMoiBankKorr5.Text + ";" + TextBoxMoiRaschetnijSchet5.Text + ";" + TextBoxMojaRukDolzhnost5.Text + ";" + TextBoxMojVlice5.Text + ";" + TextBoxMojFIORuk5.Text + ";" + TextBoxMojUrAddr5.Text + ";" + TextBoxMojFackAddr5.Text + ";" + TextBoxMojPhone5.Text + ";" + TextBoxMojMobile5.Text + ";" + TextBoxMojEmail5.Text + ";" + TextBoxMojSait5.Text + ";" + TextBoxMojSlogan5.Text + ";" + TextBoxMojLogo5.Text + ";" + TextBoxMoiPechatPodpis5.Text + ";" + TShapka + ";" + TextBoxUslugiPo5.Text + ";" + Logofilename + ";" + PechatPodpisfilename + ";"); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(Myfile5); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { this.TextBlockStatusFile5.Text = "Файл моих реквизитов " + Myfile5.Name + " успешно сохранен."; } else { this.TextBlockStatusFile5.Text = "Не удалось сохранить файл моих реквизитов " + Myfile5.Name + "."; } } else { this.TextBlockStatusFile5.Text = "Операция записи файла моих реквизитов была прервана."; } }
public async Task FileSaveAsync(InkCanvas inkCanvas) { try { UpdateModel(); var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.Desktop, DefaultFileExtension = ".gsk" }; savePicker.FileTypeChoices.Add("Skizze", new List <string>() { ".gsk" }); savePicker.SuggestedFileName = "Neue Skizze"; StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { ProgressRingActive = true; CachedFileManager.DeferUpdates(file); await _inkPageDataProvider.SaveInkPageAsync(inkCanvas, inkPage, file); Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); // Add to FA without metadata string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { //gespeichert ProgressRingActive = false; //PunkteschluesselSaveNecessity = false; } else { ProgressRingActive = false; //konnte nicht gespeichert werden } } else { //Operation abgebrochen } } catch { ProgressRingActive = false; } }
private async void Download() { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads; // Dropdown of file types the user can save the file as (MUST HAVE) // fileName should include the expected file format because the savePicker can't list all existing file format // .temp extension removed after savePicker is closed savePicker.FileTypeChoices.Add("Temporary format", new List <string>() { ".temp" }); // Default file name if the user does not type one in or select a file to replace string fileName = "107.391.029_" + "bizbasz.txt"; savePicker.SuggestedFileName = fileName; // Create file and rename to correct file format StorageFile targetFile = await savePicker.PickSaveFileAsync(); await targetFile.RenameAsync(fileName); if (targetFile != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. CachedFileManager.DeferUpdates(targetFile); // Write to file Azure.DownloadBlob("documents", targetFile); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(targetFile); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { this.upload_feedback_2.Text = "File " + targetFile.Name + " was saved."; } else { this.upload_feedback_2.Text = "File " + targetFile.Name + " couldn't be saved."; } } else { this.upload_feedback_2.Text = "Operation cancelled."; } }
private async void Save(object sender, RoutedEventArgs e) { User user = new User(); user.name = this.name.Text; user.email = this.email.Text; user.sdt = this.sdt.Text; user.dc = this.dc.Text; string Jsonmember = JsonConvert.SerializeObject(user); var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Plain Text", new List <string>() { ".txt" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "New Document"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file await Windows.Storage.FileIO.WriteTextAsync(file, Jsonmember); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { this.mess.Text = "File " + file.Name + " was saved."; } else { this.mess.Text = "File " + file.Name + " couldn't be saved."; } } else { this.mess.Text = "Operation cancelled."; } }
async private void SaveWithFilepickerAndDownload(object sender, RoutedEventArgs e) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Video", new List <string>() { ".mp4", ".mkv" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "New File"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); var stream = await file.OpenStreamForWriteAsync(); getYoutubeFileProps(stream); // write to file // await Windows.Storage.FileIO.WriteTextAsync(file, file.Name); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { this.StatusText.Text = "File " + file.Name + " was saved."; Debug.WriteLine("File created Successfully. Download started"); } else { this.StatusText.Text = "File " + file.Name + " couldn't be saved."; } } else { this.StatusText.Text = "Operation cancelled."; } }
private async void ExportPdfFile() { FileSavePicker savePicker = new FileSavePicker(); savePicker.DefaultFileExtension = ".pdf"; savePicker.SuggestedFileName = pdfFileName; savePicker.FileTypeChoices.Add("Adobe PDF Document", new List <string>() { ".pdf" }); StorageFile stFile = await savePicker.PickSaveFileAsync(); StorageFolder applicationFolder = ApplicationData.Current.LocalFolder; StorageFolder methodFolder; if (ClickStatus == 0) { methodFolder = await applicationFolder.CreateFolderAsync("runTest", CreationCollisionOption.OpenIfExists); } else { methodFolder = await applicationFolder.CreateFolderAsync("calibrate", CreationCollisionOption.OpenIfExists); } StorageFolder pdfFolder = await methodFolder.CreateFolderAsync(pdfFolderName, CreationCollisionOption.OpenIfExists); StorageFile pdfFile = await pdfFolder.GetFileAsync(pdfFileName); byte[] buffer; Stream stream = await pdfFile.OpenStreamForReadAsync(); buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, (int)stream.Length); if (stFile != null) { CachedFileManager.DeferUpdates(stFile); await FileIO.WriteBytesAsync(stFile, buffer); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(stFile); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { NotifyPopup notifyPopup = new NotifyPopup(loader.GetString("SaveSuccess")); notifyPopup.Show(); } } }
public async void Export_Experiment() { ContentDialog resultDialog; var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Multiporter Experiment File (*.mport)", new List <string>() { ".mport" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = Exp.Name; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); string xml = Serialize.Xml_Serialize_Object <Experiment>(Exp); // write to file await Windows.Storage.FileIO.WriteTextAsync(file, xml); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { resultDialog = new ContentDialog() { Title = "File saved successfully!", PrimaryButtonText = "OK" }; } else { resultDialog = new ContentDialog() { Title = "Oops... Something went wrong", PrimaryButtonText = "OK" }; } await resultDialog.ShowAsync(); } }
private async void save_btn_Click(object sender, RoutedEventArgs e) { string document; //Get the text and put it in the "document" var, can then use it as a string of text! editBox.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out document); if (!string.IsNullOrEmpty(document)) { Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Rich Text", new List <string>() { ".rtf" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = "New Document"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Prevent updates to the remote version of the file until we // finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(file); // write to file Windows.Storage.Streams.IRandomAccessStream randAccStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); editBox.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream); // Let Windows know that we're finished changing the file so the // other app can update the remote version of the file. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status != Windows.Storage.Provider.FileUpdateStatus.Complete) { Windows.UI.Popups.MessageDialog errorBox = new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved."); await errorBox.ShowAsync(); } } } else { Windows.UI.Popups.MessageDialog error = new Windows.UI.Popups.MessageDialog("There is nothing to save!!!"); await error.ShowAsync(); } }
static public async Task SaveFile(StorageFile sf, string content) { // Prevent updates to the remote version of the file until // we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.DeferUpdates(sf); // write to file await Windows.Storage.FileIO.WriteTextAsync(sf, content); // Let Windows know that we're finished changing the file so // the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(sf); }
/// Saves coloring page to specified file. private async Task Save_InkedImagetoFile(StorageFile saveFile) { if (saveFile != null) { Windows.Storage.CachedFileManager.DeferUpdates(saveFile); using (var outStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite)) { await Save_InkedImagetoStream(outStream); } Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(saveFile); } }
private async Task Save_InkedImagetoFile(StorageFile saveFile) { try { sharefile = await ApplicationData.Current.LocalFolder.CreateFileAsync("imgshare.png", CreationCollisionOption.ReplaceExisting); CachedFileManager.DeferUpdates(sharefile); using (var outStream = await sharefile.OpenAsync(FileAccessMode.ReadWrite)) { var file = await ApplicationData.Current.LocalFolder.GetFileAsync("inkSample"); CanvasDevice device = CanvasDevice.GetSharedDevice(); var image = await CanvasBitmap.LoadAsync(device, file.Path); using (var renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, image.Dpi)) { using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession()) { ds.Clear(Colors.White); ds.DrawImage(image, new Rect(0, 0, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight)); ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes()); } await renderTarget.SaveAsync(outStream, CanvasBitmapFileFormat.Png); } image.Dispose(); Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(sharefile); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { if (saveFile != null) { await sharefile.CopyAndReplaceAsync(saveFile); MainPage.ncSettings.objValue = "Photo has been saved successfully!"; MainPage.ncSettings.setSettings = "msgNotify"; inkCanvas.InkPresenter.StrokeContainer.Clear(); await Task.Delay(new TimeSpan(0, 0, 1)); this.Visibility = Visibility.Collapsed; } } } } catch (Exception) { UtilityClass.MessageDialog("An error occured while saving photo, Please try again", "An error occured"); } }
private async void LoadButton_Click(object sender, RoutedEventArgs e) { try { ClearCanvas(); FileOpenPicker openPicker = new FileOpenPicker(); openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; openPicker.FileTypeFilter.Add(".gif"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite); using (IInputStream intputStream = stream.GetInputStreamAt(0)) { await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(intputStream); } stream.Dispose(); Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { foreach (var stroke in inkCanvas.InkPresenter.StrokeContainer.GetStrokes()) { this.inkRecognizer.AddStroke(stroke); } var messageDialog = new MessageDialog("Load Success!"); await messageDialog.ShowAsync(); } else { var messageDialog = new MessageDialog("Load Failed"); await messageDialog.ShowAsync(); } } } catch (Exception ex) { var messageDialog = new MessageDialog(ex.Message); await messageDialog.ShowAsync(); } }
private async void SaveChartToPngFile(object sender, RoutedEventArgs e) { RenderTargetBitmap rtb = new RenderTargetBitmap(); await rtb.RenderAsync(LineChart); var pixelBuffer = await rtb.GetPixelsAsync(); var pixels = pixelBuffer.ToArray(); var displayInformation = DisplayInformation.GetForCurrentView(); var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("PNG Bitmap", new List <string>() { ".png" }); Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); await Windows.Storage.FileIO.WriteTextAsync(file, file.Name); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, stream); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint)rtb.PixelWidth, (uint)rtb.PixelHeight, displayInformation.RawDpiX, displayInformation.RawDpiY, pixels); await encoder.FlushAsync(); } this.viewModel2.Status = "Wykres zapisano"; } else { this.viewModel2.Status = "Wykres niezapisano"; } } else { return; } }
/// <summary> Metoda służąca do zapisywania wylosowanych liczb do pliku. </summary> private async void SaveToFile(string drawType) { string numbersToSave = ""; try { foreach (int number in numbers) { numbersToSave += number.ToString() + ", "; } var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("Plik tekstowy (.txt)", new List <string>() { ".txt" }); savePicker.SuggestedFileName = "wylosowane_liczby" + drawType; StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); await Windows.Storage.FileIO.WriteTextAsync(file, numbersToSave); // write to file Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { ShowToastNotification("Zapisano w: " + file.Path, file.Name); } else { ShowToastNotification("Błąd zapisu", file.Name); } } else { ShowToastNotification("Operacja anulowana.", ""); } } catch { ShowToastNotification("Błąd zapisu", "Nie wylosowano żadnych liczb!"); } }