PDA

View Full Version : File Locking?


gorilla1
11-03-2002, 04:41 AM
I am using a flat file as a little database on a site. Can I lock the file under ASP to ensure that two clients do not attempt to wirte the file simultaneously?

G

Mhtml
11-03-2002, 04:50 AM
.lock whatever the file variable is eg file.lock I think, I know application.lock so I'm guessing this similar.

rcreyes
11-14-2002, 06:13 AM
Actually, you don't need to lock the file, the FS (FileSystemObject) will automatically put a lock to the file until you issue a File.Close statement.

For example:
<%
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")

Set iFile = FSO.OpenTextFile ("C:\test.txt", 8) 'open for appending
If Err = 70 Then
'-- someone has the file opened
Response.Write "File Access Denied"
End If


..... some code here


iFile.Close '-- close the file

%>


Thanks,
Ray

whammy
11-14-2002, 11:54 PM
It sure will. I know this from experience.

Just TRY to write to an open file (with no error statement), lol. You will get "Permission Denied".

:)