ASP: using text files instead of databases

Posted on 2003-02-22
Medium Priority
Last Modified: 2010-04-06
I'm making a very small application that will ask users for their names and e-mail addresses when they visit a site.

My question is:

How many records will ASP support if I save them in a plain text file?

I don't want to use a database connection because I only need two fields.

Thank you in advance!
Question by:NoviceASP
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

whammy earned 150 total points
ID: 7999841
Well, as a test I just wrote my email to a text file 1 million times in a loop... no problem with that.

It was definitely pretty darn slow populating the whole list into a textarea, though.... but it did it.

If you want here's a quick and easy example I wrote for someone else which posts to itself.

It doesn't have the name field, just the email address -but you could add that in easily:


<% @Language="VBScript" %>
<% Option Explicit %>
'*************************************** FUNCTIONS

Function IsEmail(str)
   Dim ieRegEx
   Set ieRegEx = New RegExp
   ieRegEx.Pattern = "^[\w\+\'\.-]+@[\w\'\.-]+\.[a-zA-Z0-9]{2,}$"
   IsEmail = ieRegEx.Test(str)
End Function

'*********************************** DIM VARIABLES

Dim Email, SubmitNum ' Requested variables
Dim Found            ' Variable to check for duplicate emails
Dim fs, f, filepath  ' FileSystemObject variables


Email = Request.Form("Email")
SubmitNum = Request.Form("SubmitNum")
filepath = Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "\database\emaillist.txt"

'************************************ MAIN PROGRAM

SubmitNum = SubmitNum + 1

If IsEmail(Email) Then
   Call LookupEmail()
   If Found = False Then
      Call AppendEmail()
      Call DisplayThankYou()
      Call DisplayDupeMessage()
   End If
   Call DisplayForm()
End If

'******************************** END MAIN PROGRAM

'************************************* SUBROUTINES

Sub LookupEmail()
   Found = False
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set f = fs.OpenTextFile(filepath,1,True)
   Do While NOT f.AtEndOfStream AND Found = False
      If f.ReadLine = Email Then Found = True
   Set f = Nothing
   Set fs = Nothing
End Sub

Sub AppendEmail()
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set f = fs.OpenTextFile(filepath,8,True)
   Set f = Nothing
   Set fs = Nothing
End Sub

<% Sub DisplayThankYou() %><?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
   <meta http-equiv="refresh" content="3;URL=addtolist.asp" />
   <title>Thank You!</title>
   <div><span style="font-weight:bold">Thank you for subscribing!</span></div>
</html><% End Sub %>

<% Sub DisplayDupeMessage() %><?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
   <meta http-equiv="refresh" content="3;URL=addtolist.asp" />
   <title>Your email address already exists!</title>
   <div><span style="font-weight:bold">Your email address already exists in our database!</span></div>
</html><% End Sub %>

<% Sub DisplayForm() %><?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
   <title>Please enter your email address to subscribe!</title>
   <form id="addtoemaillist" method="post" action="addtolist.asp">
      <input type="text" name="Email" value="<% = Email %>" />
      <% If SubmitNum > 1 Then %>
      <span style="color:#ff0000"> * Invalid Email Address</span>
      <% End If %>
      <br />
      <input type="hidden" name="SubmitNum" value="<% = SubmitNum %>" />
      <input type="submit" value="Submit" />
</html><% End Sub %>


Expert Comment

ID: 8014931
perhaps you should take a look at XML

it is more flexible than using a text file, but yet pretty simple enough for simple task like that. a server that is capable of running ASP should be able to handle XML files just as well (with the MSXML parser)

with XSLT you can even transform the XML file into HTML for display purpose.

if you have not considered this option, i strongly recommend to look into it. it is well worth the time to know XML with ASP

Author Comment

ID: 8021250
Thank you very much!

Expert Comment

ID: 8021295

Doesn't hurt to learn XML either, once you're familiar with FSO. I haven't had much need to use XML in classic ASP but I'm sure I will in .NET... however for something simple like this, text files should be fine.

If you need to add more fields, just use some delimiter, like | after making sure you strip those from any potential entries first.

Then when you use file.ReadLine, you can split up the lines as you read them using the Split() function.

P.S. If you go here you can learn just about everything about FileSystemObject, it's where I learned:


If you play around with the examples there you can do some pretty complex stuff just using text files.

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question