C # Save File dialog box (SaveFileDialog)

Source: Internet
Author: User
Tags save file

1,savefiledialog control's property filter the file filter to display in the dialog box, for example, "text file (*.txt) |*.txt| All Files (*.*) |*.*" FilterIndex The index of the file filter selected in the dialog box, If you select the first item, set the 1 Restoredirectory Control dialog box to restore the current directory before closing addextension whether to automatically add the default extension checkfileexists checkpathexists

Before the dialog box returns, check to see if the specified path exists Container controls whether the user is prompted when the file is to be created. It is only applicable if the Validatenames is true. Defaultext Default Extension dereferencelinks

Whether to dereference a shortcut before returning from the dialog box filename The first file that is displayed in the dialog box or the last selected file initialdirector The initial directory of the dialog box Overwriteprompt control whether the user is prompted when overwriting the current file. Applies only if Validatenames is true ShowHelp enable the Help button title the character that will appear in the dialog box title bar validatenames Control Dialog Check whether the file name does not contain invalid characters or sequences

2, the SaveFileDialog event is as follows:

FileOK events to be processed when the user clicks on the "open" or "save" button helprequest events to be processed when the user clicks on the Help button

4, with the following example code can be implemented

private void Saveasdialogbtn_click (object sender, System.EventArgs e)
{
SaveFileDialog savefiledialog=new SaveFileDialog ();
savefiledialog.filter= text File |*.*| C # file |*.cs| all Files |*.* ";
savefiledialog.filterindex=2;
Savefiledialog.restoredirectory=true;
if (Savefiledialog.showdialog () ==dialogresult.ok)
{
if (Savefiledialog.showdialog () ==dialogresult.ok)
{
Fname=savefiledialog.filename;
File Fsaveas=new file (fName);
Isfilehavename=true; file://saved a file with a name
Fsaveas.writefile (richTextBox1.Text);
}
}
}

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.