C # how to extract the Save path of SaveFileDialog,

Source: Internet
Author: User

C # how to extract the Save path of SaveFileDialog,

Directly Add code

 

1 public TestOne () 2 {3 InitializeComponent (); 4 SaveFileDialog (); // call to open the SaveFileDialog save dialog box 5} 6 7 # region save Dialog Box 8 private void SaveFileDialog () 9 {10 // string localFilePath, fileNameExt, newFileName, FilePath; 11 SaveFileDialog saveFileDialog1 = new SaveFileDialog (); 12 13 // set the file type 14 saveFileDialog1.Filter = "txt files (*. txt) | *. txt | All files (*. *) | *. * "; 15 16 // set the display sequence of the default file type 17 saveFileDialog1.FilterIndex = 2; 18 19 // whether to remember the last opened directory 20 saveFileDialog1.RestoreDirectory = true in the SAVE dialog box; 21 22 // click the Save button to enter 23 if (saveFileDialog1.ShowDialog () = DialogResult. OK) 24 {25 // get file path 26 // localFilePath = saveFileDialog1.FileName. toString (); 27 28 // get the file name without path 29 // fileNameExt = localFilePath. substring (localFilePath. lastIndexOf ("\") + 1); 30 31 // get the file path without the file name 32 // FilePath = localFilePath. substring (0, localFilePath. lastIndexOf ("\"); 33 34 // Add time 35 before the file name // newFileName = DateTime. now. toString ("yyyyMMdd") + fileNameExt; 36 37 // Add character 38 to the file name // saveFileDialog1.FileName. insert (1, "dameng"); 39 40 System. IO. fileStream fs = (System. IO. fileStream) saveFileDialog1.OpenFile (); // output file 41 42 // fs output file with text or image, depending on the requirement 43} 44}

 

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.