C # Open File Dialog Box

Source: Internet
Author: User

This is the first C # program I wrote. It is used to split encyclopedia entries. the entry package is usually at least, and more than, but each task can only import 5 K. It has been manually split, which is time-consuming and laborious, and I am not patient enough, let's do something else. therefore, the quality is not high.

  

The page appears, as shown in. Click Browse.. Example

  

The Code is as follows:

   button2_Click(              .openFileDialog1 =              .openFileDialog1.FileName =              .openFileDialog1.Filter =              .openFileDialog1.FilterIndex =              .openFileDialog1.FileOk +=  System.ComponentModel.CancelEventHandler(                           (openFileDialog1.ShowDialog() ==                  filename =                 textBox2.Text =                                       }

Code Description:

* Button2 is the "Browse" button, which triggers the function after being clicked;

* Create a System. Windows. Forms. OpenFileDialog () object to open the file dialog box;

* The FileName member is the content in the text box after the file name. (My usage here is incorrect ). you can use it to get the name of the selected file. I should set a default file name or leave it blank;

* FileOk occurs when you click "open" or "save" in the file dialog box;

* Filter gets or sets the Filter string for the current file name. "This string determines the selected content in the" Save As file type "or" file type "dialog box. "

* The Fliter format is "file description | file suffix", such as "". If multiple filters exist, separate them with "|", for example, ""; (* is a wildcard)

* FilterIndex is an index. In general, it is the filtering option displayed by default. I set it to "2", so "" is displayed by default "";

* The openFileDialog1.ShowDialog () "Open File" dialog box appears;

* The returned value is DialogResult. OK (OK) or DialogResult. Cancel (Cancel );

* If you click "OK", assign openFileDialog1.FileName to filename, and use filename as the parameter to open the file to open the specified file;

* CommonDialog. ShowDialog Method

* This method implements RunDialog.

* If you click "OK" in the dialog box, DialogResult. OK; otherwise, DialogResult. Cancel is used.

* TextBox2.Text = filename; the textbox before "Browse" is textBox2. The file name is displayed here for your convenience;

The following is the MSDN content. I will first pick some useful ones. Don't blame me for being lazy ......

Run the code first:

   button1_Click(      Stream myStream =      OpenFileDialog openFileDialog1 =       openFileDialog1.InitialDirectory =      openFileDialog1.Filter =      openFileDialog1.FilterIndex =      openFileDialog1.RestoreDirectory =       (openFileDialog1.ShowDialog() ==                         ((myStream = openFileDialog1.OpenFile()) !=                                                                   MessageBox.Show( +   }

 

My code is almost the same as others (Khan)

* Is the initial file directory;

* The value of RestoreDirectory is true or false, indicating whether to store the last selected directory;

* MSDN Original: trueIf the dialog box restores the current directory to its original value if the user changed the directory while searching for files; otherwise, false./* It seems that there is a problem with Chinese translation. However, I did not know how to use it several times. I use true or false to get the same result (SWEAT )*/

Member

$ AddExtension

* Gets or sets a value that indicates whether the dialog box automatically adds an extension to the file name if the extension is omitted.

$ CheckFileExists

* If the dialog box displays a warning when the specified file name does not exist, true is used. Otherwise, false is used. The default value is true.

$ Multiselect

* Gets or sets a value indicating whether multiple files can be selected in the dialog box.

$ SafeFileName

* Get the file name and extension of the selected file in the dialog box. The file name does not contain a path.

* For example: filename = openFileDialog1.SafeFileName; then, the value of filename is only the file name and has no path;

 

 

--- Restore content end ---

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.