We have a financial system that writes a text file out that could be several 100 or even 1000 lines long. It writes the file into a txt file and can't be modified to be another file extension and then be renamed after the data has been loaded.
I have a service already written that notices that a txt file has shown up in this directory and fires off the application that needs to read this data.
I don't want to have the application which reads the data begin the process until after the financial system has written all data to the file.
I've searched all kinds of VB help sites and here is the code most refer to in various ways:
Public Function IsFileLocked(filename As String) As Boolean
Dim Locked As Boolean = False
Dim fs As FileStream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
Catch ex As IOException
Locked = True
I have my file open in Notepad to test and have the file being accessed, but it falls straight through the code and does not hit the catch. I even opened the file in Excel and had the same result.
Lost in the vast sea of .NET