another permission denied error

M

McTuble

So I'm new to ASP and set it up on my computer and just want a simple text
based guestbook where it just adds your entry to the end of the textfile and
to display just displays the contents of the textfile. So displaying the
contents is not the problem. Here is the code

<html>
<body>
<% Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
%>

<FORM action="signBook.asp" method="GET">
name:<INPUT TYPE="text" NAME="name">
message:<INPUT TYPE="text" NAME="message">
<INPUT TYPE="submit">
</FORM>
<%
n=request.querystring("name")
m=request.querystring("message")

if n<>"" And m<>"" then
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile("guestbook.txt", ForAppending, true)
f.WriteLine("This line is added to the file.")
f.Close()
end if
if n="" And m="" then
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("guestbook.txt"), 1)
Response.Write(f.ReadAll)
f.Close()
end if

%>
</body>
</html>

I get the Permission denied error on this line -> set f =
fs.OpenTextFile("guestbook.txt", ForAppending, true)

I have been all over the internet and tried giving the folders write access
through the control panel -> administrative tools -> internet information
services and I've also tried right clicking the folder and clicking on
properties. Then the security tab. Can anyone help me? It's kinda important
I get this out of the way. I am using Windows XP Professional with Service
Pack 2. Thanks guys.
 
M

McKirahan

McTuble said:
So I'm new to ASP and set it up on my computer and just want a simple text
based guestbook where it just adds your entry to the end of the textfile and
to display just displays the contents of the textfile. So displaying the
contents is not the problem. Here is the code

<html>
<body>
<% Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
%>

<FORM action="signBook.asp" method="GET">
name:<INPUT TYPE="text" NAME="name">
message:<INPUT TYPE="text" NAME="message">
<INPUT TYPE="submit">
</FORM>
<%
n=request.querystring("name")
m=request.querystring("message")

if n<>"" And m<>"" then
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile("guestbook.txt", ForAppending, true)
f.WriteLine("This line is added to the file.")
f.Close()
end if
if n="" And m="" then
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("guestbook.txt"), 1)
Response.Write(f.ReadAll)
f.Close()
end if

%>
</body>
</html>

I get the Permission denied error on this line -> set f =
fs.OpenTextFile("guestbook.txt", ForAppending, true)

I have been all over the internet and tried giving the folders write access
through the control panel -> administrative tools -> internet information
services and I've also tried right clicking the folder and clicking on
properties. Then the security tab. Can anyone help me? It's kinda important
I get this out of the way. I am using Windows XP Professional with Service
Pack 2. Thanks guys.

Your files are in different locations as
"guestbook.txt"
and
Server.MapPath("guestbook.txt")
are not the same.

Try this. Watch for word-wrap.

<%@ Language="VBScript" %>
<% Option Explicit
'*
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'*
Dim n
n = request.querystring("name")
Dim m
m = request.querystring("message")
'*
Dim dat
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim otf
Dim txt
txt = Server.MapPath("guestbook.txt")
'*
if n<>"" And m<>"" then
Set otf = fso_OpenTextFile(txt, ForAppending, true)
otf.WriteLine("This line is added to the file.")
else
Set otf = fso_OpenTextFile(txt, ForReading)
dat = Replace(otf.ReadAll,vbCrLf,"<br>")
Response.Write(dat)
end if
'*
Set otf = Nothing
Set fso = Nothing
%>
<html>
<body>
<FORM action="guestbook.asp" method="GET">
name: <INPUT TYPE="text" NAME="name">
message: <INPUT TYPE="text" NAME="message">
<INPUT TYPE="submit">
</FORM>
</body>
</html>
 
R

Ray Costanzo [MVP]

Hi McTuble,

After you did the "right clicking the folder and clicking on properties.
Then the security tab," what did you do? Did you modify the permissions at
all? IN an typical setup, IUSR_name_of_your_computer will need read/write
permissions to the file you're trying to modify.

Ray at work
 
M

McTuble

Thanks McKirahan it was exactly that. I just changed set f =
fs.OpenTextFile("guestbook.txt", ForAppending, true) to set f =
fs.OpenTextFile(Server.MapPath("guestbook.txt"), ForAppending, true). Thanks
as well to you Ray for trying to help me. I had indeed changed the file
permissions. I was just explaining that I used both of those methods to do
so. Also thanks for the quick response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top