File sharing problems

Hi there,

I have two applications:

First one is written by someone else and writes to several log files, some it appends to and some it over writes. I dont know the fequency in which it writes to these, but i would say fair oftem maybe every second.

Second one is written by me and what i want to do is read these files every minutes. I am having problems where when I have one of the files open the first application reports that there is a sharing violation and that it cannot write to the file.

What i would like to know is: is there a way for me to open these files in VB without causing the other application to error and say there is a sharing violation. i have tried a couple of methods, including using the filecopy method, but have not had any luck. If anyone has any ideas that would be great.


Who is Participating?
ampapaConnect With a Mentor Commented:
pinmj001, you might try creating a copy of the file and then reading your information from the copy and then delete the copy avoiding the file share issue altogether?
inthedarkConnect With a Mentor Commented:
Point 1

If you want to open a file and let another app write to the file then you need to open like this for sequenatial read operations:

lfn = FreeFile
Open "C:\MyFolder\MyFile.log" For Input Shared As lfn

Or like this for more flexible binary (read from any point any amount) operations):

lfn = FreeFile
Open "C:\MyFolder\MyFile.log" For Binary Access Read Shared As lfn

Point 2

However, you still have a problem because the software in the other app may not have included the "Share" attribute when they are appending, writing or reading from a file.  In which case you need to ask the chap to correct his code.

For example, many people thinK that this is how you open and read a file:

lfn = FreeFile
Open "C:\MyFolder\MyFile.log" For Input As lfn ' shoddy code asking for trouble
All Courses

From novice to tech pro — start learning today.