public string BrowseDestination(Window owner, string destination, string extension) { using (var dialog = new FileSaveDialog()) { GetFilePathInfo(destination, out var folderPath, out var fileName, out var fileExtension); dialog.SetClientGuid(new Guid("486640B6-B311-4EFD-A15F-616F51FAAF5B")); dialog.SetDefaultFolder(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); dialog.SetTitle("Destination file of the image to be created"); dialog.SetOkButtonLabel("Select"); dialog.SetCancelButtonLabel("Cancel"); dialog.SetFileNameLabel("Destination file :"); dialog.SetDefaultExtension(extension.Substring(1)); dialog.SetFileTypes($"Image files (*{extension})|*{extension}|All files (*.*)|*.*"); dialog.SetFileTypeIndex(fileExtension == null || fileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) ? 1 : 2); dialog.DontAddToRecent = true; if (fileName != null) { dialog.SetFileName(fileName); } if (PathHelper.DirectoryExists(folderPath)) { dialog.SetFolder(folderPath); } return(dialog.ShowDialog(owner) == true?dialog.GetResult() : null); } }
public void DownloadFile(byte[] fileBytes) { Invoke((Action)(() => { FileSaveDialog.ShowDialog(); })); var myStream = FileSaveDialog.OpenFile(); myStream.Write(fileBytes, 0, fileBytes.Length); myStream.Close(); }
private void FileDialogButton_Click(object sender, EventArgs e) { FileSaveDialog.ShowDialog(); var path = FileSaveDialog.FileName; if (string.IsNullOrWhiteSpace(path)) { return; } FileNameTextBox.Text = path.Trim(); SetFileTypeBasedOnExtension(path); }
public void Save() { OnDisable(); Filter[] filters = new ShellFileDialogs.Filter[] { new ShellFileDialogs.Filter("JSON", "json"), new ShellFileDialogs.Filter("All files", "*") }; string selection = FileSaveDialog.ShowDialog(System.IntPtr.Zero, "Save VMC protocol dump", initialDirectory: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), defaultFileName: "packets.json", filters: filters, selectedFilterZeroBasedIndex: 0); if (selection == null || selection == "") { OnEnable(); return; } string json = JsonConvert.SerializeObject(messages, Formatting.Indented); File.WriteAllText(selection, json); OnEnable(); }
private void ExportToFileButton_Click(object sender, EventArgs e) { FileSaveDialog.InitialDirectory = Directory.GetCurrentDirectory(); if (FileSaveDialog.ShowDialog() == DialogResult.OK) { try { JsonFileSerializer.SerializeSnapshotsToJson(ImportedDatabase, FileSaveDialog.OpenFile()); } catch (Exception Ex) { if (Ex is JsonSerializationException || Ex is JsonReaderException) { GUIHelper.ThrowWarning("File error", "Serialization failed."); } } } }
private void btnSave_Click(object sender, EventArgs e) { if (listCD.Count == 0) { MessageBox.Show("You don't have any item to be saved", "Saving Error", MessageBoxButtons.OK); return; } DialogResult save = FileSaveDialog.ShowDialog(); if (save == DialogResult.OK) { string filename = FileSaveDialog.FileName; //tạo file hoặc nếu file tồn tại thì ghi đè lên tất cả nội dung cũ File.WriteAllText(filename, ""); int count = 0; foreach (CDInformation cd in listCD) { string songs = ""; //get songs for (int i = 0; i < cd.Song.Count; i++) { songs += cd.Song[i]; if (i < cd.Song.Count - 1) { songs += "#"; } } //create string write to file string CDInfo = string.Format("{0}~{1}~{2}~{3}~{4}~{5}", cd.ID1, cd.Album1, cd.Singer1, cd.Genre1, cd.Duration, songs); if (count > 0) { File.AppendAllText(filename, Environment.NewLine); } File.AppendAllText(filename, CDInfo); count++; } } }
private void FileOpRename_Click(object sender, EventArgs e) { var selSpecPath = SelectedSpecificationPath; var dlg = new FileSaveDialog(mRoot) { FileName = Path.GetFileNameWithoutExtension(selSpecPath) }; if (dlg.ShowDialog() != DialogResult.OK) { return; } var filePathNoExtn = Path.Combine(mRoot.UserSpecificationFolder, dlg.FileName); var filePath = Path.ChangeExtension(filePathNoExtn, FileExtensions.MacroFileExtension); if (File.Exists(filePath)) { File.Delete(filePath); } File.Move(selSpecPath, filePath); RefreshSpecificationsList(SearchBox.Text.ToLower(CultureInfo.CurrentCulture)); }
public static string Save() { return(FileSaveDialog.ShowDialog(IntPtr.Zero, "Save .wowvrc file", null, null, _filters, 0)); }
[STAThread] // <-- " If the attribute is not present, the application uses the multithreaded apartment model, which is not supported for Windows Forms." public static Int32 Main(String[] args) { Console.WriteLine("Now showing a folder browser dialog. Press [Enter] to continue."); _ = Console.ReadLine(); // FolderBrowserDialog { String selectedDirectory = FolderBrowserDialog.ShowDialog(parentHWnd: IntPtr.Zero, title: "Select a folder...", initialDirectory: null); if (selectedDirectory != null) { Console.WriteLine("Folder browser. Selected directory: \"{0}\".", selectedDirectory); } else { Console.WriteLine("Folder browser. Cancelled."); } } Console.WriteLine("Now showing an open-file dialog to select multiple files (with multiple extension filters). Press [Enter] to continue."); _ = Console.ReadLine(); // FileOpenDialog { Filter[] filters = new Filter[] { new Filter("Images", "gif", "png", "jpg", "jpeg", "heic", "webp"), new Filter("Videos", "mov", "wmv", "mp4", "mpeg", "mpg", "avi", "webm"), new Filter("Audio", "mp3", "wma", "wav", "aac"), new Filter("All files", "*"), }; IReadOnlyList <String> fileNames = FileOpenDialog.ShowMultiSelectDialog(IntPtr.Zero, title: "Open multiple files...", initialDirectory: @"C:\Users\David\Music", defaultFileName: null, filters: filters, selectedFilterZeroBasedIndex: 2); if (fileNames != null) { Console.WriteLine("Open file dialog. Selected files:"); foreach (String fileName in fileNames) { Console.WriteLine(fileName); } } else { Console.WriteLine("Open file dialog. Cancelled."); } } Console.WriteLine("Now showing an open-file dialog to select a single file (with a single extension filter). Press [Enter] to continue."); _ = Console.ReadLine(); // FileOpenDialog { const String windowsFormsFilter = @"Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"; // from https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filter(v=vs.110).aspx IReadOnlyList <Filter> filters = Filter.ParseWindowsFormsFilter(windowsFormsFilter); IReadOnlyList <String> fileNames = FileOpenDialog.ShowMultiSelectDialog(IntPtr.Zero, title: "Open a single file...", initialDirectory: @"C:\Users\David\Music", defaultFileName: null, filters: filters, selectedFilterZeroBasedIndex: 2); if (fileNames != null) { Console.WriteLine("Open file dialog. Selected files:"); foreach (String fileName in fileNames) { Console.WriteLine(fileName); } } else { Console.WriteLine("Open file dialog. Cancelled."); } } Console.WriteLine("Now showing an save-file dialog to save a single file (with multiple extension filters). Press [Enter] to continue."); _ = Console.ReadLine(); // FileSaveDialog { Filter[] filters = new Filter[] { new Filter("Images", "gif", "png", "jpg", "jpeg", "heic", "webp"), new Filter("Videos", "mov", "wmv", "mp4", "mpeg", "mpg", "avi", "webm"), new Filter("Audio", "mp3", "wma", "wav", "aac"), new Filter("All files", "*"), }; String initialDirectory = @"C:\Users\David\Music\Aerosmith\2006 - The Very Best Of\"; String defaultFileName = /*initialDirectory +*/ @"12 - Aerosmith - Dream On.mp3"; String fileName = FileSaveDialog.ShowDialog(IntPtr.Zero, "Save a file...", initialDirectory, defaultFileName, filters, selectedFilterZeroBasedIndex: 2); if (fileName != null) { Console.WriteLine("Save file dialog. Selected file: \"{0}\".", fileName); } else { Console.WriteLine("Save file dialog. Cancelled."); } } Console.WriteLine("Shell file dialogs demo completed. Press [Enter] to exit."); _ = Console.ReadLine(); return(0); }
public static void Main(string[] args) { // FolderBrowserDialog { String selectedDirectory = FolderBrowserDialog.ShowDialog(IntPtr.Zero, "Title", null); if (selectedDirectory != null) { Console.WriteLine("Folder browser. Selected directory: \"{0}\".", selectedDirectory); } else { Console.WriteLine("Folder browser. Cancelled."); } } // FileOpenDialog { Filter[] filters = new Filter[] { new Filter("Images", "gif", "png", "jpg", "jpeg", "heic", "webp"), new Filter("Videos", "mov", "wmv", "mp4", "mpeg", "mpg", "avi", "webm"), new Filter("Audio", "mp3", "wma", "wav", "aac"), new Filter("All files", "*"), }; String[] fileNames = FileOpenDialog.ShowMultiSelectDialog(IntPtr.Zero, "Title", @"C:\Users\David\Music", defaultFileName: null, filters: filters, selectedFilterZeroBasedIndex: 2); if (fileNames != null) { Console.WriteLine("Open file dialog. Selected files:"); foreach (String fileName in fileNames) { Console.WriteLine(fileName); } } else { Console.WriteLine("Open file dialog. Cancelled."); } } // FileOpenDialog { const String windowsFormsFilter = @"Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"; // from https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filter(v=vs.110).aspx Filter[] filters = Filter.ParseWindowsFormsFilter(windowsFormsFilter); String[] fileNames = FileOpenDialog.ShowMultiSelectDialog(IntPtr.Zero, "Title", @"C:\Users\David\Music", defaultFileName: null, filters: filters, selectedFilterZeroBasedIndex: 2); if (fileNames != null) { Console.WriteLine("Open file dialog. Selected files:"); foreach (String fileName in fileNames) { Console.WriteLine(fileName); } } else { Console.WriteLine("Open file dialog. Cancelled."); } } // FileSaveDialog { Filter[] filters = new Filter[] { new Filter("Images", "gif", "png", "jpg", "jpeg", "heic", "webp"), new Filter("Videos", "mov", "wmv", "mp4", "mpeg", "mpg", "avi", "webm"), new Filter("Audio", "mp3", "wma", "wav", "aac"), new Filter("All files", "*"), }; String initialDirectory = @"C:\Users\David\Music\Aerosmith\2006 - The Very Best Of\"; String defaultFileName = /*initialDirectory +*/ @"12 - Aerosmith - Dream On.mp3"; String fileName = FileSaveDialog.ShowDialog(IntPtr.Zero, "Title", initialDirectory, defaultFileName, filters, selectedFilterZeroBasedIndex: 2); if (fileName != null) { Console.WriteLine("Save file dialog. Selected file: \"{0}\".", fileName); } else { Console.WriteLine("Save file dialog. Cancelled."); } } }