I'm having some problems with file access to a log file that my program is writing to. I have it all set up fine and it logs the data being pulled off the network to a file. But when I copy and paste that log file with windows explorer (XP) or I open the file with a log viewer program that I've made there are access errors. I've caught the errors in a try catch loop
I'm not sure what explorers problem is, but I can open the file with notepad or wordpad and no file exceptions are thrown. But the log reader program will make the logging program throw exceptions. How do I a) make my logging program safe so that explorer will not cause it to throw exceptions (or do I just catch the exceptions and live with it) and b) make the log reading program open the file in such a way that it doesn't make the log program throw errors.
The log reader opens the file like this:
Thanks in advance for any help,
Nathan
VB.NET:
Public Sub write_data_to_file(ByVal filePath As String, ByVal tempString As String)
Static Dim alreadyDisplayed As Boolean = False
Dim yesNo As DialogResult
Try
logWrite = New StreamWriter(filePath, True)
logWrite.WriteLine(tempString)
logWrite.Close()
Catch ex As IOException
If (Not alreadyDisplayed) Then
alreadyDisplayed = True
yesNo = MessageBox.Show(ex.Message, "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Warning)
alreadyDisplayed = False
End If
End Try
End Sub
I'm not sure what explorers problem is, but I can open the file with notepad or wordpad and no file exceptions are thrown. But the log reader program will make the logging program throw exceptions. How do I a) make my logging program safe so that explorer will not cause it to throw exceptions (or do I just catch the exceptions and live with it) and b) make the log reading program open the file in such a way that it doesn't make the log program throw errors.
The log reader opens the file like this:
VB.NET:
Dim objReader As New System.IO.StreamReader(logFilePath)
Thanks in advance for any help,
Nathan