Print Page | Close Window

Writing to a text file

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14583
Printed Date: 28 March 2026 at 9:00pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Writing to a text file
Posted By: elbeardo
Subject: Writing to a text file
Date Posted: 06 April 2005 at 1:01pm
Ok i couldn't do this from scratch so im using an example i found. What it is, is a form which writes the inputted text to a text file. When i submit the form though, it just says done and the text hasnt been written and the second part of the asp isn't written to the screen.
Anyhoo, heres the code if anyone can help me:

<%
'Check to see if title has been entered or not
u_title=request.form("u_title")
if u_title = "" then
%>
<!-- Input form area - This will only display when no Title has been entered -->
<form method="POST" action="<%= request.servervariables("script_name") %>">

<p>Document Title<br>
<input type="text" name="u_title" size="35"></p>
<p>Font Size<br>
<select size="1" name="u_text_size">
<option selected value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
&nbsp;
</select></p>
<p>Paragraph 1<br>
<textarea rows="2" name="u_paragraph1" cols="35"></textarea></p>
<p>Paragraph 2<br>
<textarea rows="2" name="u_paragraph2" cols="35"></textarea><input type="submit" value="Submit" ></p>
</form>
<%
end if
%>

<%
if u_title <> "" then
' If there is a user inputted title
' get all of the user inputed values
u_title=request.form("u_title")
u_paragraph1=request.form("u_paragraph1")
u_paragraph2=request.form("u_paragraph2")
u_text_color=request.form("u_text_color")
u_text_size=request.form("u_text_size")
g_filename=replace(u_title," ","_")


set fso = createobject("scripting.filesystemobject")
' create the text (html) file to the server adding the -mmddyyyy after the g_title value
Set act = fso.CreateTextFile("D:\Inetpub\wwwroot\test.txt", true)
 
' write all of the user input to the text (html) document
' The .htm extension can just as easily be .asp or .inc whatever best suits your needs
act.WriteLine "<html>"
act.WriteLine chr(13)
act.WriteLine "<title>"& u_title &"</title>"
act.WriteLine chr(13)
act.WriteLine "<body bgcolor='#FFFFFF'>"
act.WriteLine chr(13)
act.WriteLine "<p align='center'><font face='arial' size='"& u_text_size &"'>"
act.WriteLine chr(13)
act.WriteLine u_title &"</p>"
act.WriteLine chr(13)
act.WriteLine "<p align='left'><font face='arial' size='"&u_text_size&"'>"
act.WriteLine chr(13)
act.WriteLine u_paragraph1 &"</p>"
act.WriteLine chr(13)
act.WriteLine "<p align='left'><font face='arial' size='"& u_text_size &"'>"
act.WriteLine chr(13)
act.WriteLine u_paragraph2 &"</p>"
act.WriteLine chr(13)
act.WriteLine "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
act.WriteLine "<p align='center'><font face='arial' size='"& u_text_size &"'>"
act.WriteLine "This document was created on&nbsp;"
act.WriteLine now() &"</p>"

' close the document
act.Close
%>
Your page has been successfully create and can be viewed by clicking
<a href="D:\Inetpub\wwwroot\test.txt">here</a>
<br>
<br>
<% response.write "<html>"
response.write chr(13)
response.write "<title>"& u_title &"</title>"
response.write chr(13)
response.write "<body bgcolor='#FFFFFF'>"
response.write chr(13)
response.write "<p align='center'><font face='arial' size='"& u_text_size &"'>"
response.write chr(13)
response.write u_title &"</p>"
response.write chr(13)
response.write "<p align='left'><font face='arial' size='"&u_text_size&"'>"
response.write chr(13)
response.write u_paragraph1 &"</p>"
response.write chr(13)
response.write "<p align='left'><font face='arial' size='"& u_text_size &"'>"
response.write chr(13)
response.write u_paragraph2 &"</p>"
response.write chr(13)
response.write "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
response.write "<p align='center'><font face='arial' size='"& u_text_size &"'>"
response.write "This document was created on&nbsp;"
response.write now() &"</p>"
end if
%>

If anyone could help i would be extremely grateful.
rob


-------------
dude



Replies:
Posted By: ub3rl337ch3ch
Date Posted: 06 April 2005 at 7:21pm
for starters, you'll want to change the link for the file from d:\inetpub\wwwroot\test.txt to http://localhost/test.txt - http://localhost/test.txt , though i doubt that will be having any impact, it will mean that you're actually keeping all your links in a web format, instead of relying on local drive paths
 
aside from that, i don't  know much about file manipulation, but should act always be fso.CreateTextFile? wouldn't that make a new text file each time you call act? or is it supposed to work like that?


Posted By: elbeardo
Date Posted: 06 April 2005 at 7:28pm
Yes, a new file created each time is what i am intending but i want the first line always to be, "test= "  (for reading into Flash purposes).

Thanks for the reply,
rob


Posted By: elbeardo
Date Posted: 08 April 2005 at 6:14pm
Hmm...still having trouble with this Cry

If anyone could give me some hints i'd be most appreciative,
rob


Posted By: dj air
Date Posted: 08 April 2005 at 6:20pm
to have test= as the first liune

you need ot

add as the first line

act.writeline "test="

a good site for fso and other features is www.devguru.com


Posted By: elbeardo
Date Posted: 08 April 2005 at 6:24pm
Yeah cheers. I've already got the test= as the first line but didnt bother to post the new code again.

Cool thanks for the url...will look some more into it!

rob



Posted By: elbeardo
Date Posted: 15 April 2005 at 10:58am
Ok i've just been working on a simpler version of this so i can post info from a flash file. Thought this would work as theres less to go wrong but it doesnt seem to be doing anything and the local host just doesnt really do much.
<%
Dim fso, DataFile, schoolNews
Set fso = Server.CreateObject("Scripting.FileSystemObject")
DataFile = Server.MapPath("/localhost/project/schoolNews.txt")
Set schoolNews = fso.OpenTextFile(DataFile, 2, true)
schoolNews.write("schoolNews=")
schoolNews.Write "&paragraph1="
schoolNews.Write Request.Form("paragraph1")
schoolNews.Write "&paragraph2="
schoolNews.Write Request.Form("paragraph2")
schoolNews.Write "&paragraph3="
schoolNews.Write Request.Form("paragraph3")

schoolNews.Close
%>

i reckon its something pretty simple but i can't see it.
Any help would be greatly appreciated again!
rob


Posted By: Demon
Date Posted: 15 April 2005 at 12:20pm
Is flash POSTing or GETing the info?

-------------
So Sayith the Demon.


Posted By: elbeardo
Date Posted: 15 April 2005 at 12:22pm
its POSTing!

Thanks,
rob



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net