File Handling
File Handling
File Handling
Form design:
Codes:
OpenFileDialog1.InitialDirectory = "E:\DDAP2013\VBExercises\texts\"
OpenFileDialog1.Title = "Opening a file"
OpenFileDialog1.Filter = "Text Files|*.txt"
OpenFileDialog1.ShowDialog()
txt1.Text = textline
objReader.Close() ' must be closed after use.
Else
MsgBox("File do not exist.")
End If
End Sub
objWriter.Write(txt1.Text)
objWriter.Close()
MsgBox("Text written to file")
Else
End If
End Sub
SaveFileDialog1.OverwritePrompt = True
SaveFileDialog1.InitialDirectory = "E:\DDAP2013\VBExercises\texts\"
SaveFileDialog1.Title = "Saving your file"
SaveFileDialog1.ShowDialog()
Dim FILE_NAME As String = SaveFileDialog1.FileName
End Sub
OpenFileDialog1.InitialDirectory = "E:\DDAP2013\VBExercises\texts\"
OpenFileDialog1.Filter = "Text Files|*.txt"
OpenFileDialog1.Title = "Choose a file to copy"
OpenFileDialog1.ShowDialog()
SaveFileDialog1.OverwritePrompt = True
SaveFileDialog1.InitialDirectory = "E:\DDAP2013\VBExercises\texts\"
SaveFileDialog1.Title = "Saving your file"
SaveFileDialog1.ShowDialog()
FileToCopy = OpenFileDialog1.FileName
NewCopy = SaveFileDialog1.FileName & ".txt"
System.IO.File.Copy(FileToCopy, NewCopy)
MsgBox("File Copied")
End Sub
OpenFileDialog1.InitialDirectory = "E:\DDAP2013\VBExercises\texts\"
OpenFileDialog1.Filter = "Text Files|*.txt"
OpenFileDialog1.Title = "Choose a file to copy"
OpenFileDialog1.ShowDialog()
FileToMove = OpenFileDialog1.FileName
System.IO.File.Move(FileToMove, MoveLocation)
MsgBox("File Moved")
End If
End Sub
OpenFileDialog1.InitialDirectory = "E:\DDAP2013\VBExercises\texts\"
OpenFileDialog1.Filter = "Text Files|*.txt"
OpenFileDialog1.Title = "Choose a file to delete"
OpenFileDialog1.ShowDialog()
fileToDelete = OpenFileDialog1.FileName