© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

  HomeSource Code DotNet ►VB.Net▼

FileDialog

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

 

 

 

 

SLogix Student Projects


⇓Student Projects⇓
⇑Student Projects⇑
bottom