Description:
We can populate save file dialog and
save our file, open the existing file through open file dialog, read that
opened file and write the data into rich textbox control.
Save File Dialog
With SaveFileDialog1
.DefaultExt = "txt"
.FileName = strFileName
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Demo Save File Dialog"
End
With
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
'Save the file name
strFileName = SaveFileDialog1.FileName
Dim filePath As String
'Open or Create the file
filePath = System.IO.Path.Combine( _
My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
strFileName)
'Replace the contents of the file
My.Computer.FileSystem.WriteAllText(filePath, RichTextBox1.Text, False)
Catch fileException As Exception
Throw fileException
End Try
End If
Open File Dialog
With OpenFileDialog1
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.Title = "Demo Open File Dialog"
End With
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim allText As String
Try
'Save the file name
strFileName = OpenFileDialog1.FileName
'Read the contents of the file
allText = My.Computer.FileSystem.ReadAllText(strFileName)
'Display the file contents in the TextBox
RichTextBox1.Text = allText
Catch fileException As Exception
Throw fileException
End Try
End If
Contact:
Mr. Roshan P. Helonde
Mobile: +91-7276355704
WhatsApp: +91-7276355704
Email: roshanphelonde@rediffmail.com