Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Form Posting to a .txt file
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

JJenson
Advanced Member

USA
2121 Posts

Posted - 17 August 2007 :  00:00:43  Show Profile  Visit JJenson's Homepage
I have been looking all over msdn and on google and I cannot find a chuck of code or anything to be able to post data from a form into a text file.

I need it so that it either creates a new file for every form that gets submitted or if possible it could just add to the end of 1 .txt file.

Can anyone point me in a direction of something that tells me how to do this?

THanks

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 17 August 2007 :  06:09:48  Show Profile  Send ruirib a Yahoo! Message
Here is some code that illustrates it:


set fso = server.createObject("scripting.FileSystemObject")
strFolderCkName = ("c:\test\")

strExportFilename = "export.txt"

If not fso.FolderExists(strFolderCkName) then  'if the folder does not exist, creates it...
    fso.createFolder(strFolderCkName)
end if

'Now create a new file

set exportFile = fso.createtextfile(strFolderCkName & strExportFilename,true)
'on error resume next

'write to the file
exportFile.write "Testing writing into a text file" &  vbNewline
exportFile.write "This is a field from a form:" & Request.Form("MyFormField") & vbNewLine


With this you should be all set.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 17 August 2007 :  09:24:32  Show Profile  Visit JJenson's Homepage
Great thanks Rui
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 20 August 2007 :  21:00:44  Show Profile  Visit JJenson's Homepage
Ok Rui I ran into a problem and I cannot seem to find much in my google searches.

THis is the code and how I have modified it:


<%
set fso = server.createObject("scripting.FileSystemObject")
strFolderCkName = ("c:\emails\")

strExportFilename = "export.txt"

If not fso.FolderExists(strFolderCkName) then 'if the folder does not exist, creates it...
fso.createFolder(strFolderCkName)
end if

'Now create a new file

set exportFile = fso.createtextfile(strFolderCkName & strExportFilename,true)
'on error resume next

'write to the file
exportFile.write "Testing writing into a text file" & vbNewline
exportFile.write "First Name:" & Request.Form("Fname") & vbNewLine
exportFile.write "Last Name:" & Request.Form("Lname") & vbNewLine
exportFile.write "Email:" & Request.Form("Email") & vbNewLine
exportFile.write "Telephone Number:" & Request.Form("Phonenumber") & vbNewLine
exportFile.write "Store Number:" & Request.Form("Location") & vbNewLine
exportFile.write "Comments:" & Request.Form("Comments") & vbNewLine

%>


Now when I do this I got this error

error '800a0046'
/confirmationTest.asp, line 42

This is that line:

set exportFile = fso.createtextfile(strFolderCkName & strExportFilename,true)


I am not sure how to solve this? THanks so much for the suggestions everyone.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 21 August 2007 :  02:14:14  Show Profile  Send ruirib a Yahoo! Message
Does the anonymous internet account have permissions to create the file on that folder?


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 21 August 2007 :  05:07:31  Show Profile
You'll also need to add a check that the file doesn't already exist before creating it if you're dumping the details into the same file each time.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 21 August 2007 :  08:54:35  Show Profile  Visit JJenson's Homepage
How would I do that Shaggy? I will check on that Rui.
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 21 August 2007 :  09:19:32  Show Profile  Visit JJenson's Homepage
OK I just want to know if what I was told is true in any way. I called into the host and asked them to put the anonymous user account to have permissions to create the file within that directory.

They told me they can do this but that it is a huge security risk because if someone gains access and submits a script into that text file they could gain access to the drive.

Persoanlly this seems a little far fetched but wanted to know if this is real or a host saying things they don't really know?

Thanks
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 21 August 2007 :  09:32:05  Show Profile  Send ruirib a Yahoo! Message
In theory yes, they are right... however, many servers are configured to allow that and no actual access has occurred.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 21 August 2007 :  09:55:39  Show Profile  Visit JJenson's Homepage
IS there a workaround to do it another way?
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 21 August 2007 :  09:58:18  Show Profile  Send ruirib a Yahoo! Message
No, I'm afraid not. The user needs write permission to write to the file, no way around that.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 21 August 2007 :  10:17:08  Show Profile  Visit JJenson's Homepage
Ok will just double check with the person that this is a possiblity in theory but that many are configured like this and make sure they still want this feature.

Thanks Rui
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 21 August 2007 :  21:47:28  Show Profile  Visit JJenson's Homepage
OK the anonymous user has fill permissoins and I still get the same error. I am not to sure where to go from here? ANy suggestions help would be wonderful?

Thanks again for the suggestions so far they have been very helpful in learning this
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 21 August 2007 :  22:01:22  Show Profile  Visit JJenson's Homepage
Nevermind did some more searching and I got it working. THanks again Rui and Shaggy for the help.

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.28 seconds. Powered By: Snitz Forums 2000 Version 3.4.07