Helpful Information
 
 
Category: ASP
write to page permantately

how would one using a simple form write text to a page forever,until the page with the text in is deleted.

thanks in advance.
scroots

you'd have to use the file system object.

Are you writing to a text file, html file, etc.?

Let me know, in the mean time I'll write you a good example of writing stuff to a text file.

~Quack

Or, you can check out the examples at:

http://www.w3schools.com

They should get you started !

But....

Make sure that the web server has write permissions enabled on the folder containing the file. Or less you'll be plegued with access denied errors.

it would be written to a html file .
thanks everyone.

scroots

Sorry scroots, completely forgot about my promise....

as promised, here's a simple example of how to write to an html file... (actually - this creates the file...)

<%@Language=VBScript%>
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile("FULL_PATH_TO_YOUR_FILE", true)
fs.writeline("<html>")
fs.writeline("</html>")
fs.Close
set fs = nothing
set fso = nothing
%>

Hope this gives you some insight ... althought I'm sure you may have figured all this out already.

~Quack

Hey, if you want to add text to an exisiting file, change:

CreateTextFile("FULL_PATH_TO_YOUR_FILE", True)

to

OpenTextFile("FULL_PATH_TO_YOUR_FILE")

If you have more questions, post and we'll help :D

~Quack

thanks guys i`m a liitle busy at the moment thanks for your replies its for a litle project i`m making.

scroots

got the idea but i need it from a simple form (text area) with a send button.
it will help me learn ASP.

please;) ;)

scroots

Easiest way to do this is just read from the textarea and write it to the file.... it may not be formatted in the nicest looking way, but the output will stay the same...

Html page


<form action="YOUR_ASP_PAGE.ASP" method="post">
<textarea rows="10" cols="30" name="theText"></textarea>
<br>
<input type="submit">
</form>


in the ASP page that you submit your form to, have the line
fs.write(Request.Form("theText")) instead of the fs.writeline statements.

ASP Page


<%@Language=VBScript%>
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile("FULL_PATH_TO_YOUR_FILE", true)
fs.write(Request.Form("theText"))
fs.Close
set fs = nothing
set fso = nothing
%>
That should do the trick,

let me know if you need any clarification.

~Quack

thank you, i understand now.

thanks

scroots

No problem.

:thumbsup:

~Quack

quack my code i have done doesn`t write to a file or even make a file. could you please help me, my code:
the form page:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<form action="myasp.asp" method="post">
<textarea rows="10" cols="30" name="theText"></textarea>
<br>
<input type="submit">
</form>

</body>

</html>


the other page (myasp.asp):
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<%@Language=VBScript%>
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile("my.txt", true)
fs.write(Request.Form("theText"))
fs.Close
set fs = nothing
set fso = nothing
%>

</body>

</html>

the first page does the form action (sends to myasp.asp) but myasp.asp does not write to a file.
can anyone help?

scroots

That worked fine for me - however I had to map the path to the directory on my server (database) that has write permissions.:

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<%@Language=VBScript%>
<%

sMapPath = Server.MapPath("\")
sMapPath = Mid(sMapPath, 1, InStrRev(sMapPath,"\")-1) & "\database\my.txt"

Set fso = Server.CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile(sMapPath, true)
fs.write(Request.Form("theText"))
fs.Close
set fs = nothing
set fso = nothing
%>

</body>

</html>

Are you getting an error, or what?

it doesn`t create or write to the file.

scroots

i`m testing it on my PC using PWS, my other ASP (counter) script works, so i doubt it is PWS.

scroots

If it's not doing either one (or either), you should *definitely* be getting an error. Are you sure you're looking in the right place?!?










privacy (GDPR)