The Winform control SaveFileDialog is used to save files.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.