Forum Moderators: open

Message Too Old, No Replies

ASP-FSO writing to a text file

doesn't write to the text file

         

magyar

7:22 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Hello,
I'm creating a simple text file database (must be text file-not access database)for registering users on a website. Everything works, the newly registered users' details are emailed to him, etc etc....except it doesn't write to the text file. Here's the code:
<%
Dim strCompany,strPhone,strEmail,strPassword,myFSO,pwdObj,WriteRecord,Record1

strCompany = Request.Form("company")
strPhone = Request.Form("phone")
strPassword = Request.Form("pwd")
strEmail = CStr(Request.Form("email"))

Set pwdObj=Server.CreateObject("Scripting.FileSystemObject")
Set gtFile = pwdObj.OpenTextFile(Server.MapPath("logon.txt"))

Dim strLine
'checks if user exists

While Not gtFile.AtEndOfStream
strLine = gtFile.ReadLine

If InStr(strLine, strEmail) Then
gtfile.Close
Response.Redirect "userexists.asp"
End If
WEND

strEmail = Request.Form("email")

Record1 = (strCompany&" "&strEmail&" "&strPassword&" "&strPhone)

Set myFSO = CreateObject("Scripting.FileSystemObject")

Set WriteRecord = myFSO.OpenTextFile("register.txt",8, True)

WriteRecord.WriteLine(Record1)
WriteRecord.Close

SET WriteRecord = NOTHING
Object named myFSO
SET myFSO = NOTHING
%>
It doesn't write anything to 'register.txt'
What am I missing?
thanks
magyar

Prolific

7:59 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Most likely it's a permissions problem. Check the permission on that file or the directory that the file is located in. you'll need to enable write access for the IIS anonymous account (usually: iusr_servername)

emsaw

8:42 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



magyar,

I would try using Server.MapPath to write the file into a directory relative to the script that is running. I ran it on my machine as you provided and received the same error.. then used Server.MapPath , and it wrote out successfully to the script directory..


Set WriteRecord = myFSO.OpenTextFile(Server.MapPath("randomfilename.txt"),8, True)

HTH,

Mark

magyar

2:42 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Yes you are both right. I made a mistake about the Server.MapPath coding. Also I needed to get the 'write' permissions fixed with the server.

Thanks your replies
magyar