SQL PHP HTML ASP JavaScript articles and free scripts to download

Appending data to file in ASP

We have seen how we can write data to a text file. While writing the old data of the file is always deleted, so to add new data ( fresh ) every time we can use write method. Some time we may need to keep the old data and add new date to the file. Here we have to use the append mode to write to a file. In append mode new data is written or added at the end of the file.

Please read the tutorial on writing data to a file using FSO. In the same ASP ( VBScript) script if the mode is changed to append mode then the data will be written at the end of the file without deleting the old data. So just change the constant value and the mode of the file opening. Here are the changes required.

Const Appending=8
Set OpenFileobj = FSOobj.OpenTextFile(FilePath, Appending)

You can easily locate the above two changes in the script given at write data tutorial and replace it.

Now let us try something different for our understanding using this file appends method. We will develop one form to store the email submitted by the users. Each time one visitor submits an email address it has to be added at the end of the file. Note that this is not a newsletter script and many other features like checking the email address etc are not discussed here. This is to be used only to understand how the file appends system works.

We will display one simple form which submits to itself and if the length of the data submitted is more than 2 char length then by using one if condition we will execute the append script.

Please create a blank file as text.txt in the same directory and execute the script. Here is the full code.

<form method=post action=''>
<input type=text name=email><input type=submit value=Submit>
</form>
<%
Dim email
email = Request("email")
if len(email) > 2 Then
Const Appending=8
Dim OpenFileobj, FSOobj,FilePath
FilePath=Server.MapPath("text.txt") ' located in the same directory
Set FSOobj = Server.CreateObject("Scripting.FileSystemObject")
if FSOobj.fileExists(FilePath) Then
Set OpenFileobj = FSOobj.OpenTextFile(FilePath, Appending)
OpenFileobj.WriteLine(email)
OpenFileobj.Close
Set OpenFileobj = Nothing
Else
Response.Write "File does not exist"
End if
Set FSOobj = Nothing
End if
%>


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer