WinForm Control SaveFileDialog code example for saving a file usage

Source: Internet
Author: User
Tags save file
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:

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.