Once a user has selected a file with the open file dialog, how can I handle this action? For example, if the user has selected a .txt file and has opened it, how can it get the
You want to handle the FileOk event:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim path As String = OpenFileDialog1.FileName
If fileIsBitmap Then
' say the file is a bitmap image '
Dim bmp As New Bitmap(path)
' rotate the image 90 degrees '
bmp.RotateFlip(RotateFlipType.Rotate90FlipNone)
' save the image '
bmp.Save(path)
ElseIf fileIsTextFile Then
' or say the file is a text file '
Dim fs As New IO.FileStream(path, IO.FileMode.Append)
Dim sr As New IO.StreamWriter(fs)
' write a new line at the end of the file '
sr.WriteLine("This is a new line.")
' close the FileStream (this saves the file) '
sr.Close()
fs.Close()
End If
End Sub