C# FileDialog file selection

1、SaveFileDialog

            OpenFileDialog openfile = new OpenFileDialog();
            //Initial display file directory//openfile.InitialDirectory = @"";
            openfile.Title = "Please select the file to send.";
            //Filter file type
            openfile.Filter = "Text file |*.txt| executable file |*.exe|STOCK|STOCK.txt| all file types * * *.";
            if (DialogResult.OK == openfile.ShowDialog())
            {
                //Assign the full path of the selected file to the text box.
                textBox1.Text = openfile.FileName;
            }
      

2、SaveFileDialog

 

 SaveFileDialog savefile = new SaveFileDialog();
            //If the name of the file is not written, the suffix name is automatically added * *. The suffix name will not be automatically added.
            savefile.AddExtension = true;
            savefile.Filter = "Executable file |*.exe| text file |*.txt|STOCK|STOCK.txt| all files * *.";
            if(DialogResult.OK==savefile.ShowDialog())
            {
                textBox1.Text = savefile.FileName;
            }

 

Leave a Reply

Your email address will not be published. Required fields are marked *