SaveFileDialog in Visual Basic .NET

SaveFileDialog is another important dialog box which can be used to save file

This is the code used to save the text of the TextBox to TXT file

Code explanation

  • Line 5 : Default extension is txt. If you do not specify the file extension when you save the file, default one will be taken
  • Line 6 : If the file is already there it will ask for overwrite dialog as shown in below image

  • Line 7 : Using filter for text files
  • Line 11: Check for Windows.Forms.DialogResult.OK to execute the code
  • Line 13: Open the StreamWriter and pass the file name parameter come with SaveFileDialog1.FileName
  • Line 14: Write the Text to Stream