The Winform control SaveFileDialog is used to save files.
SaveFileDialog is used to save files for your reference. The specific content is as follows:
1. Create a Winform application named SaveFileDialogDemo.
2. Add a button control on the interface (used to open the save file dialog box) and a text control to enter the content to save.
3. 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> /// <param name = "e"> </param> private void btn_SaveFile_Click (object sender, eventArgs e) {// SaveFileDialog sfd = new SaveFileDialog (); // set the title of the Save file dialog box sfd. title = "select the file path to save"; // initialize the Save directory, default exe file directory sfd. initialDirectory = Application. startupPath; // set the type of the saved file. sfd. filter = "text file | *. txt | audio file | *. wav | image file | *. jpg | all files | *. * "; if (sfd. showDialog () = DialogResult. OK) {// get the path to save the 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 and enter the content to save in the text box:
5. Click "save file" to open the "save file" dialog box, enter the file name, and click "save:
6. You can view the Save dialog box .txt file under the debugdirectory. open the file and view the saved content:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.