Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2011, 12:47 PM
Registered User
 
Join Date: Aug 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to write to beginning of file

Hi everybody,

The question is as follows, i am using a free script called "Zero Administration Guestbook" which the complete code can be found here:
myanmars.net/download/zaguestbook-asp.htm

The script works fine but the only thing is that new messages are placed at the bottom of the generated .htm file each time.
How can i change the ASP code so that it will place the newest messages at the top of the page instead?

Again, help is much appreciated as i have absolutely no grasp on ASP (am a frontend developer)

Cheers and thanks in advance!
 
Old August 23rd, 2011, 06:29 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Almost impossibe to help you other than saying to move the code that writes the message up the page.

FYI you are not using the forum very well. Generally you would post the offending code, point and describe the issue, help others hep you!..........ISorry to say but IME on forums nobody is going to download the code to help you
__________________
Wind is your friend
Matt
 
Old August 23rd, 2011, 11:42 PM
Registered User
 
Join Date: Aug 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Mat41 for your reply and apologies for not placing the code.

The code is as follows:

HTML Code:
<%
'-----------------------------------------
' ZERO ADMINISTRATION GUESTBOOK - Ver 1.30
' Copyright 2000-05 by Steven HTUT, Myanmars.NET. All rights reserved.
' dev@myanmars.net
'
' This asp code can be used/distributed free of charge, and
' this copyright notice should not be altered.
'-----------------------------------------
' SETUP INSTRUCTIONS
' Pls see at http://www.myanmars.net/download/zaguestbook-asp.htm
'-----------------------------------------
' CONFIGURE YOUR GUESTBOOK
'
Dim strFile, bDay, strBakFile, strDump, SiteTitle, WelcomeMessage, TextAttribute, LineAttribute, BodyAttribute, StyleDesp
SiteTitle 	= "My Zero Administration Guestbook"
WelcomeMessage	= "Welcome to our guestbook. Please tell us what kind of thoughts, comments, or suggestions you have about our site..."
strFile 	= Server.MapPath("/writeable-directory/guestbook.htm")
strLog 		= Server.MapPath("/writeable-directory/guestbook.log")
LineAttribute 	= "<hr size='1' color='red'>"   			'note the use of single quotes
TextAttribute 	= "<font face='Comic Sans MS' size='3' color='navy'>"
BodyAttribute	= "<body bgcolor='#FFFFFF' link='#FF0000'>"		'note the use of single quotes
StyleDesp	= "<style><!--	body { font-family: sans-serif; font-size: 10pt }	A:hover { color: white; background-color: red; }	A:link { color: red; }	-->	</style>"

'-----------------------------------------
' DON'T EDIT BELOW THIS LINE (except <!--#include virtual... line)
'-----------------------------------------

If Request.Form.Count = 0 Then
%>
	<html><head>
	<title>
	<%
	response.write (SiteTitle)
	%>
	Guestbook: thoughts, comments, suggestions...</title>
	<% response.write (StyleDesp) %>
	</head>
	<% response.write (BodyAttribute) %>

	<H1>
	<% response.write (SiteTitle) %>
	Guestbook</H1>
	<% response.write (WelcomeMessage) %>
	<FORM ACTION="guestbook.asp" METHOD="post">
	<TABLE>
		<TR>
		<TD ALIGN="right" VALIGN="top"><B>Comment:</B></TD>
		<TD><textarea rows="9" name="comment" cols="90"></textarea>
		<TR>
		<TD ALIGN="right"><B>Name:</B></TD>
		<TD><INPUT TYPE="text" NAME="name" SIZE="30"></TD>
		</TR>
		<TR>
		<TD ALIGN="right" valign="top"><B>Email:</B></TD>
		<TD><INPUT TYPE="text" NAME="email" SIZE="30"><p>
	<INPUT TYPE="submit" VALUE="Sign the Guestbook!"></INPUT></TD></TR>
	</TABLE>
	</FORM>&nbsp;<p>

	<blockquote>
	<H3>Thoughts, Comments, and Suggestions on
	<%
	response.write (SiteTitle) & "<br>"
	response.write (MonthName(month(date)) & " " & year(date))
	%>
	</H3>
	<!--#include virtual="/writeable-directory/guestbook.htm"-->
	</blockquote>
<%
	response.Write (LineAttribute)
Else
	'### CHECK DATE -- IF ANOTHER MONTH, BACKUP FILE
	Dim objFSO, objFSOlog
	Dim objFile, objFileLog

	'### READ DATE LOG
	Set objFSOlog = Server.CreateObject("Scripting.FileSystemObject")
	Set objFileLog = objFSOlog.OpenTextFile(strLog, 1)		'### OPEN GUESTBOOK.LOG
	bDay = objFileLog.ReadAll
	bDay = Trim(bDay)
	objFileLog.Close

	'### IF A MONTH ENDED
	If Day(Date) < cByte(bDay) then
		If Month(Date) = 1 then 
		  strBakFile = Server.MapPath("" + Trim(CStr(year(date)-1)) +"-"+ "12.htm")
		else
		  strBakFile = Server.MapPath("" + Trim(CStr(year(date))) +"-"+ Trim(CStr(month(date)-1)) + ".htm")
		End if
		response.write (strBakFile & "<br>")
		'### DO BACK UP
		'### READ OLD GUESTBOOK
		Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
		Set objFile = objFSO.OpenTextFile(strFile, 1)		'### OPEN guestbook.htm
		strDump = objFile.ReadAll
		objFile.Close
		Set objFile = Nothing
		Set objFSO = Nothing
		'### WRITE TO BAK FILE
		Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
		Set objFile = objFSO.CreateTextFile(strBakFile, true)
		objFile.write ("<html><head>")
		objFile.write (StyleDesp + "</head>")
		objFile.write (BodyAttribute)
		objFile.write ("<h3>Guestbook of Year "+ Trim(CStr(year(date))) +", Month "+ Trim(CStr(month(date)-1))+"</h3>")
		objFile.write (strDump)
		objFile.write ("</body></html>")
		objFile.Close
		Set objFile = Nothing
		Set objFSO = Nothing
		'### INITIATE CURRENT GUESTBOOK
		Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
		Set objFile = objFSO.CreateTextFile(strFile, true)
		objFile.write ("<hr size='1' color='red'>")
		objFile.Close
		Set objFile = Nothing
		Set objFSO = Nothing
		response.write ("Guestbook for the new month initiated...")
	End If


	'### Write the results to file
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(strFile, 8, True)
	objFile.Write (LineAttribute)
	objFile.Write (TextAttribute)
	objFile.Write Server.HTMLEncode(Request.Form("comment"))
	objFile.Write "</p><p align='right'>"
	objFile.Write Server.HTMLEncode(Request.Form("name"))
	objFile.Write ", <a href='mailto:" & Server.HTMLEncode(Request.Form("email")) & "'>"
	objFile.Write Server.HTMLEncode(Request.Form("email")) & "</a></font><br><font size='1'>"
	objFile.Write now & " - ip address:"
	objFile.Write (request.servervariables("remote_Addr")) & "</font></p>"
	objFile.Close

	'### WRITE DATE LOG
	Set objFileLog = objFSOlog.OpenTextFile(strLog, 2, True)
	objFileLog.Write Day(Date)
	objFileLog.Close
	Set objFile = Nothing
	Set objFSO = Nothing
	Set objFileLog = Nothing
	Set objFSOlog = Nothing
%>

	<H3>Your comments have been written to the file!</H3>
	<A HREF="./guestbook.asp">Back to the guestbook</A><p>
<%
End If
%>

<A HREF="http://www.myanmars.net/download/zaguestbook-asp.htm">Zero Administration ASP Guestbook</a>. ASP code programmed by Steven HTUT from <A HREF="http://www.myanmars.net">Myanmar</a>.
</body></html>
The code automatically writes a log file and htm file with all the guestbook entries.
I just don't understand how i can tell the script to write to the beginning of the file instead of the bottom of the file.

Also, after every month a new file is created.
To simplify i just want everything to be placed in just 1 single file.
Deleting the code responsible for it to create another file did not work and gave back an error.


Thanks in advance

Last edited by dikkkers; August 23rd, 2011 at 11:45 PM.. Reason: additional info
 
Old August 24th, 2011, 02:55 AM
Registered User
 
Join Date: Aug 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This thread can be closed / deleted as a different script is being used instead.
The current one proved to be very limited and difficult to customize

Thanks anyway!





Similar Threads
Thread Thread Starter Forum Replies Last Post
write to file angelboy C# 2005 4 March 25th, 2007 05:01 AM
write file abaso.jadhav01 ASP.NET 2.0 Basics 0 November 24th, 2006 06:15 PM
How to write to text file ? method Beginning VB 6 1 April 13th, 2006 01:54 AM
why does this over write the previous file starsailor Pro JSP 0 December 6th, 2004 03:53 PM
reading HTML from file -> write to file mikeuk Beginning PHP 4 July 21st, 2004 05:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.