Forum Moderators: open

Message Too Old, No Replies

Directory permissions

For reading a file with FileSystemObject

         

TheDave

1:02 am on Sep 10, 2003 (gmt 0)

10+ Year Member



Ok, I'm gonna break my knuckles if I punch anything again. Why tf won't this work:

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Filename = Server.MapPath("data\file.txt")
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile(Filename, ForReading)

I have set the data directory, through the Internet Services Manager, to have Read and Write permissions, with Script permissions set to none. What's really driving me crazy is it won't cause an error, just hang the browser indefinately. Even more annoying is that this does work and returns true when the file exists:

if fs.FileExists(Filename)

Its times like these I wish I wasn't so used to using M$ crap.

duckhunter

2:46 am on Sep 10, 2003 (gmt 0)

10+ Year Member



Try setting the permissions using the OS level options. (Windows Explorer then right click on the file or folder then properties and add the user rights under the Security Tab)

If you are using classic ASP then IUSR_machinename will need the read rights, if it's .NET then the ASPNET user will need them.

TheDave

3:11 am on Sep 10, 2003 (gmt 0)

10+ Year Member



Actually I did try this, but to no avail. I added a new IUSR_NAME (that's also the anonymous login name is that correct?) and gave it Read/Write permissions, because I do want to write eventually too! :P Any other suggestions I'm really stumped :¦

GaryK

8:52 pm on Sep 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you stating that if you test for the existence of this file first then your code snippet will run and not hang-up the browser? If so, and in the absence of any error handling code, if the file doesn't exist your code snippet should cause a crash. Either way I think the best situation is to check for the file first and then take the appropriate action.

bcolflesh

9:02 pm on Sep 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The createNewFile param should be true:

sloppycode.net/fso/?m=76

TheDave

11:10 pm on Sep 10, 2003 (gmt 0)

10+ Year Member



Oh yes I am doing that :) I just posted the part of the code which was most relevant to the problem, entire:


Const ForReading = 1, ForWriting = 2, ForAppending = 8

Filename = Server.MapPath("data\messages.txt")
set fs = Server.createObject("Scripting.FileSystemObject")

if not request.form("update") = "" then
if fs.FileExists(Filename) then
set f = fs.OpenTextFile(Filename, ForWriting)
else
set f = fs.CreateTextFile(Filename, true)
end if
f.write request.form("messages")
set f = nothing
end if

if fs.FileExists(Filename) then
set f = fs.OpenTextFile(Filename, ForReading)
messages = f.readall()
end if

set f = nothing
set fs = nothing

I think I'm just going to have to set the permissions on the file itself, as thats what I had to do for a database. I havn't tried this yet I just got back in.

<pre> tag is a bit screwy here :/ Of all places!

duckhunter

3:42 am on Sep 12, 2003 (gmt 0)

10+ Year Member



Two things to try:
1) f.close the file before setting it to nothing. Could be locked. Stop/Start IIS to make sure it doesn't have it open.

2) Try using the "ForAppending" param instead of the "ForWriting"