This article mainly for you in detail the WinForm SaveFileDialog Save the File dialog box relevant information, with a certain reference value, interested in small partners can refer to
SaveFileDialog is used to save the file for your reference, the specific content is as follows
1. Create a new WinForm form application named Savefiledialogdemo.
2. Add a button control on the interface (to open the Save File dialog box) and add a text control to enter the content you want to save.
3, the Background code implementation:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.io;using system.linq;using system.text;using system.threading.tasks;using System.Windows.Forms; namespace savefiledialogdemo{public partial class Form1:form {public Form1 () {InitializeComponent (); }///<summary>///Save File button///</summary>//<param name= "sender" ></param>//&L T;param name= "E" ></param> private void Btn_savefile_click (object sender, EventArgs e) {//Savefi Ledialog sfd = new SaveFileDialog (); Sets the title of the Save File dialog box SFD. Title = "Please select the file path to save"; Initialize save directory, default exe file directory SFD. InitialDirectory = Application.startuppath; Set the type of save file SFD. Filter = "text file |*.txt| audio file |*.wav| picture file |*.jpg| all Files |*.*"; if (SFD. ShowDialog () = = DialogResult.OK) {//Get the path to the saved file string filePath = sfd. FileName; Save using (FileStream Fswrite = new FileStream (FilePath, FileMode.OpenOrCreate, FileAccess.Write)) {byte[] buffer = Encoding.Default.GetBytes (txt _fileinfo.text.tostring (). Trim ()); Fswrite.write (buffer, 0, buffer.) Length); } } } }}
4, run the EXE program, enter the content to be saved in the text box:
5, click the "Save File" button, open the Save file dialog, enter the file name, click Save:
6. In the debug directory below you can see the Save dialog box. txt this file, open the file, you can see the contents of the Save: