prayank.gahlot
Member
- Joined
- Apr 28, 2016
- Messages
- 5
- Programming Experience
- 1-3
In my vb.net application there is a requirement that the program should read the contents of a log file after every 24 hours and flush the file contents so that new logs can be added to it then.
I can easily add the timer to do this on regular time intervals but facing problems in getting the code to read and delete the contents of the log file. I am reading the contents of the file using the below code:
Using sr As New StreamReader(TextBox3.Text)
line = sr.ReadToEnd()
End Using
TextBox3 has the location of the text file defined by the user at run time.
I read this code on a different forum but it doesn't fit in my scenario although I thought this is pretty close to what I wanted. But, it reads lines and deletes by line numbers. I want to read the whole content and delete it. The reason I want to read the contents is because I want to save it in a variable and pass the variable contents to another function in the code which send this logs to a server which saves the archived logs.
I can easily add the timer to do this on regular time intervals but facing problems in getting the code to read and delete the contents of the log file. I am reading the contents of the file using the below code:
Using sr As New StreamReader(TextBox3.Text)
line = sr.ReadToEnd()
End Using
TextBox3 has the location of the text file defined by the user at run time.
I read this code on a different forum but it doesn't fit in my scenario although I thought this is pretty close to what I wanted. But, it reads lines and deletes by line numbers. I want to read the whole content and delete it. The reason I want to read the contents is because I want to save it in a variable and pass the variable contents to another function in the code which send this logs to a server which saves the archived logs.
- Dim text As Array
- Dim lines As New List(Of String)
-
- text = File.ReadAllLines(data_path & "notes.txt")
- lines.AddRange(text)
- Array.Clear(text, 0, text.Length)
- lines.RemoveAt(lines.IndexOf(value))
- text = lines.ToArray()
- file.WriteAllLines(data_path & "notes.txt", text)