Public Class Form1
Private Sub btnCreatePath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreatePath.Click
Dim sPath As String = ""
Dim sFile As String = ""
Dim sPathFile As String = ""
sPath = txtPath.Text.ToString & "\"
sFile = txtFile.Text.ToString
txtMsg.Text = ""
sPathFile = sPath & sFile
Try
System.IO.Directory.CreateDirectory(sPath)
Catch ex As Exception
txtMsg.Text = "Create Directory " & sPath & " fail"
End Try
End Sub
Private Sub btnCreateFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateFile.Click
Dim sPath As String = ""
Dim sFile As String = ""
Dim sPathFile As String = ""
sPath = txtPath.Text.ToString & "\"
sFile = txtFile.Text.ToString
txtMsg.Text = ""
sPathFile = sPath & sFile
Dim fsFileStream As System.IO.FileStream = Nothing
Dim swStreamWriter As System.IO.StreamWriter = Nothing
Try
fsFileStream = New System.IO.FileStream(sPathFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite)
swStreamWriter = New System.IO.StreamWriter(fsFileStream)
swStreamWriter.WriteLine("Test StreamWriter Start")
swStreamWriter.WriteLine("System.IO.FileMode.Create")
swStreamWriter.WriteLine("Test StreamWriter Start")
swStreamWriter.WriteLine()
Catch ex As Exception
txtMsg.Text = "Create " & sPathFile & " fail"
Finally
If Not swStreamWriter Is Nothing Then
swStreamWriter.Close()
End If
If Not fsFileStream Is Nothing Then
fsFileStream.Close()
End If
End Try
End Sub
Private Sub btnAppendFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAppendFile.Click
Dim sPath As String = ""
Dim sFile As String = ""
Dim sPathFile As String = ""
sPath = txtPath.Text.ToString & "\"
sFile = txtFile.Text.ToString
txtMsg.Text = ""
sPathFile = sPath & sFile
Dim fsFileStream As System.IO.FileStream = Nothing
Dim swStreamWriter As System.IO.StreamWriter = Nothing
Try
fsFileStream = New System.IO.FileStream(sPathFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite)
swStreamWriter = New System.IO.StreamWriter(fsFileStream)
swStreamWriter.WriteLine("Test StreamWriter Start")
swStreamWriter.WriteLine("System.IO.FileMode.Append")
swStreamWriter.WriteLine("Test StreamWriter Start")
swStreamWriter.WriteLine()
Catch ex As Exception
txtMsg.Text = "Append " & sPathFile & " fail"
Finally
If Not swStreamWriter Is Nothing Then
swStreamWriter.Close()
End If
If Not fsFileStream Is Nothing Then
fsFileStream.Close()
End If
End Try
End Sub
Private Sub btnExistsPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExistsPath.Click
Dim sPath As String = ""
sPath = txtPath.Text.ToString & "\"
txtMsg.Text = ""
If System.IO.Directory.Exists(sPath) = True Then
txtMsg.Text = "Exists " & sPath
Else
txtMsg.Text = "Not exists " & sPath
End If
End Sub
Private Sub btnExistsFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExistsFile.Click
Dim sPath As String = ""
Dim sFile As String = ""
Dim sPathFile As String = ""
sPath = txtPath.Text.ToString & "\"
sFile = txtFile.Text.ToString
txtMsg.Text = ""
If System.IO.File.Exists(sPathFile) = True Then
txtMsg.Text = "Exists " & sPathFile
Else
txtMsg.Text = "Not exists " & sPathFile
End If
End Sub
Private Sub btnDeleteFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteFile.Click
Dim sPath As String = ""
Dim sFile As String = ""
Dim sPathFile As String = ""
sPath = txtPath.Text.ToString & "\"
sFile = txtFile.Text.ToString
txtMsg.Text = ""
sPathFile = sPath & sFile
Try
System.IO.File.Delete(sPathFile)
Catch ex As Exception
txtMsg.Text = "Delete " & sPathFile & " fail"
End Try
End Sub
Private Sub btnMoveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveFile.Click
Dim sPath As String = ""
Dim sFile As String = ""
Dim sPathFile As String = ""
Dim sToPath As String = ""
Dim sToFile As String = ""
Dim sToPathFile As String = ""
sPath = txtPath.Text.ToString & "\"
sFile = txtFile.Text.ToString
sPathFile = sPath & sFile
sToPath = txtToPath.Text.ToString & "\"
sToFile = txtToFile.Text.ToString
sToPathFile = sToPath & sToFile
txtMsg.Text = ""
Try
System.IO.File.Move(sPathFile, sToPathFile)
Catch ex As Exception
txtMsg.Text = "Move " & sPathFile & " fail"
End Try
End Sub
End Class