| 

.NET C# Java Javascript Exception

1
Eine Frage zu ;
Listbox Item in LOG TXT ständig mit schreiben wenn Checkbox = true

Wie erreiche ich das wenn der Button gedrückt istund in Listbox geschrieben wird auch
automatisch alle Listboxeinträge in die TXT ständig mitschreibt!

Hat einer eine Idee!

GRUSS TM

CODE
-------------------------
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'FileSystemWatcher.IncludeSubdirectories = False
Dim lw() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives '#### Noch nicht impentiert 1. HD Buchstben auslesen 11032020
FileSystemWatcher.EnableRaisingEvents = False
Dim filters() As String
filters = [Enum].GetNames(GetType(IO.NotifyFilters))
Dim filter As String
For Each filter In filters
CheckedListBox1.Items.Add(filter)
Next
CheckedListBox1.SetItemChecked(1, True)
CheckedListBox1.SetItemChecked(2, True)
CheckedListBox1.SetItemChecked(3, True)
TXTFileTypes.Text = "*.*" '#### 11032020
TXTPath.Text = System.AppDomain.CurrentDomain.BaseDirectory '#### 11032020
Button1.Text = "Starten Sie die Überwachung" 'Start Monitoring
'##### CHECKBOX Text
CheckBox1.Text = "LOG"



End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Button1.Text = "Starten Sie die Überwachung" Then
If TXTPath.Text.Trim.Length = 0 Then
MsgBox("Bitte wählen Sie einen Ordner aus, der auf Dateiänderungen überwacht werden soll") 'Please select a folder to monitor for file changes
Exit Sub
End If
If TXTFileTypes.Text.Trim.Length = 0 Then
MsgBox("Bitte geben Sie die zu überwachenden Dateitypen an") 'Please specify the file types to monitor
Exit Sub
End If
FileSystemWatcher.Filter = TXTFileTypes.Text.Trim
FileSystemWatcher.Path = TXTPath.Text.Trim
FileSystemWatcher.NotifyFilter =
IO.NotifyFilters.Attributes Or IO.NotifyFilters.CreationTime Or
IO.NotifyFilters.DirectoryName Or IO.NotifyFilters.FileName Or
IO.NotifyFilters.LastAccess Or IO.NotifyFilters.LastWrite Or
IO.NotifyFilters.Security Or IO.NotifyFilters.Size
FileSystemWatcher.EnableRaisingEvents = True
FileSystemWatcher.IncludeSubdirectories = True '#### 10.03.2020
Button1.Text = "Beenden Sie die Überwachung"
Else
FileSystemWatcher.EnableRaisingEvents = False
FileSystemWatcher.IncludeSubdirectories = False '#### 10.03.2020
Button1.Text = "Starten Sie die Überwachung"
End If
'#### So hier das XML TXT Logging implementieren.....
If CheckBox1.Checked = True Then
'Aktion
LOG()


ElseIf CheckBox1.Checked = False Then
'Aktion
' Nichts unternehmen.....
'LOG()
End If


End Sub

Private Sub FileSystemWatcher_Changed(sender As Object, e As IO.FileSystemEventArgs) Handles FileSystemWatcher.Changed
ListBox1.Items.Add(e.ChangeType.ToString & vbTab & e.FullPath & "-" & Date.Now) 'Changed Created Deleted - Ereignis - Zeilenumbruch einfügen
End Sub

Private Sub FileSystemWatcher_Renamed(ByVal sender As Object,
ByVal e As System.IO.RenamedEventArgs) Handles _
FileSystemWatcher.Renamed

ListBox1.Items.Add("RENAMED" & vbTab & e.OldFullPath & " TO " & e.FullPath & "-" & Date.Now)
End Sub

Private Sub FileSystemWatcher_Error(ByVal sender As Object,
ByVal e As System.IO.ErrorEventArgs) Handles _
FileSystemWatcher.Error
If FileSystemWatcher.EnableRaisingEvents Then
FileSystemWatcher.EnableRaisingEvents = False
FileSystemWatcher.InternalBufferSize = 2 *
FileSystemWatcher.InternalBufferSize
FileSystemWatcher.EnableRaisingEvents = True
End If
End Sub

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

End Sub
Private Sub LOG()
'Dim text As String = ""
'For Each Litem As String In ListBox1.Items
'Text &= vbCrLf & Litem
' Next
' IO.File.WriteAllText("C:\Users\Public\Downloads\Pathcrawler.txt", text)

Dim SaveFileDialog As New SaveFileDialog
SaveFileDialog.FileName = ""
SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

If SaveFileDialog.ShowDialog() = DialogResult.OK Then
Dim sb As New System.Text.StringBuilder()

For Each o As Object In ListBox1.Items
sb.AppendLine(o)
Next

System.IO.File.WriteAllText(SaveFileDialog.FileName, sb.ToString())
End If

End Sub
End Class
27.07.2020
tsmeier 51 1 3