Advertisement
bhushan23

file_handling in vb.net

Oct 4th, 2012
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.82 KB | None | 0 0
  1. Public Class Form1
  2.  
  3.  
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.         Dim f_name = "c:\" + Filename_box.Text + ".txt"
  6.         Dim readobj As New System.IO.StreamReader(f_name)
  7.         Dim combo As String
  8.         combo = ComboBox1.Text
  9.         If combo = "Read line by line" Then
  10.             MsgBox(readobj.ReadLine)
  11.  
  12.         ElseIf combo = "read to end" Then
  13.             RichTextBox1.Text = readobj.ReadToEnd()
  14.  
  15.         End If
  16.         readobj.Close()
  17.     End Sub
  18.  
  19.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  20.         Dim f_name = "c:\" + Filename_box.Text + ".txt"
  21.         Dim writeobj As New System.IO.StreamWriter(f_name)
  22.         If System.IO.File.Exists(f_name) = True Then
  23.             writeobj.Write(RichTextBox1.Text)
  24.             MsgBox("Written to file")
  25.         Else
  26.             System.IO.File.Create(f_name)
  27.             MsgBox("file " & f_name & " created ")
  28.             writeobj.Write(RichTextBox1.Text)
  29.         End If
  30.  
  31.         writeobj.Close()
  32.     End Sub
  33.  
  34.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  35.         Dim f_name = "c:\" + Filename_box.Text + ".txt"
  36.         Dim appendobj As New System.IO.StreamWriter(f_name)
  37.         Dim combo As String
  38.        
  39.  
  40.         If System.IO.File.Exists(f_name) = True Then
  41.             combo = ComboBox2.Text
  42.             If combo = "Append from same line" Then
  43.  
  44.                 appendobj.Write(RichTextBox1.Text)
  45.                 Button3.Visible = True
  46.             ElseIf combo = "Append from next line" Then
  47.  
  48.                 appendobj.WriteLine(RichTextBox1.Text)
  49.                 Button3.Visible = True
  50.             End If
  51.         Else
  52.             MsgBox("file" & f_name & "doesn't exists !!!")
  53.         End If
  54.  
  55.         appendobj.Close()
  56.     End Sub
  57.  
  58.    
  59.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  60.         Dim file1 As String
  61.         Dim file2 As String
  62.         file2 = "c:\" + copybox.Text + ".txt"
  63.         file1 = "c:\" + Filename_box.Text + ".txt"
  64.         System.IO.File.Copy(file1, file2)
  65.         MsgBox("file " & file1 & " copied to " & file2)
  66.  
  67.     End Sub
  68.  
  69.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  70.         Dim file1 As String
  71.         Dim file2 As String
  72.         file2 = "c:\" + movebox.Text + ".txt"
  73.         file1 = "c:\" + Filename_box.Text + ".txt"
  74.         System.IO.File.Move(file1, file2)
  75.         MsgBox("file " & file1 & " moved to " & file2)
  76.     End Sub
  77.  
  78.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  79.         Dim file As String
  80.         file = "c:\" + Filename_box.Text + ".txt"
  81.         If System.IO.File.Exists(file) = True Then
  82.             System.IO.File.Delete(file)
  83.             MsgBox("file " & file & " deleted")
  84.         Else
  85.             MsgBox("file " & file & " Doesn't exists")
  86.         End If
  87.  
  88.     End Sub
  89.  
  90.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  91.         Button1.Visible = True
  92.  
  93.     End Sub
  94.  
  95.     Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
  96.         Button3.Visible = True
  97.     End Sub
  98.     Private Sub copybox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles copybox.TextChanged
  99.         Button4.Visible = True
  100.     End Sub
  101.  Private Sub movebox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movebox.TextChanged
  102.         Button6.Visible = True
  103.    
  104. End Sub
  105.     End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement