Simple Filemanagement in Vb.net
for basic programmers

This is the Demo for the file management.

Class Function

Imports

System.IO

Namespace

Common

Public Class Functions

Public Sub CreateTextFile(ByVal FileName As String)

If Not File.Exists(FileName) Then

If (MessageBox.Show("Do you want to create the" & FileName & "?", "Theva", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then

Using sw As StreamWriter = File.CreateText(FileName)

sw.Close()

End Using

Else

MessageBox.Show(

"File  hasn't created")

End If

End If

End Sub

Public Sub AppendTextToFile(ByVal FileName As String, ByVal AppendText As String)

' Create an instance of StreamWriter to write text to a file.

Using sw As StreamWriter = New StreamWriter(FileName)

' Add some text to the file.

If (MessageBox.Show("Do you want to add the " &  " & AppendText & " & "to the file of " & FileName & "?", "Theva", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK) Then

sw.WriteLine(AppendText)

Else

MsgBox(

"Type the proper details")

End If

sw.Close()

End Using

End Sub

End Class

End

Namespace

Backeend coding.

Imports Common.Functions

Public

Class Form1

Dim obj1 As New Common.Functions

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

obj1.CreateTextFile(TextBox2.Text.Trim)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

obj1.AppendTextToFile(TextBox2.Text.Trim, TextBox1.Text.Trim)

clear()

End Sub

Sub clear()

TextBox2.Text =

""

TextBox1.Text =

""

End Sub

End

Class