When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Text Files and ASP


Let's face it, there are times when you really want to do nothing more than write a small, compact text file on the server. We've all longed to do that, and ASP makes it painfully easy. In fact, ASP allows you to do a plethora of other file-related tasks as well (for example, read the contents of a directory, display the size of a file, determine if a folder exists or not).

To do all of these nifty things, we need to use the FileSystemObject. This object is discussed in detail in Ryan S.'s article Reading/Writing Text Files in ASP. You can also list out the contents of a directory using the FileSystemObject. I strongly recommend that you also take some time reading the complete documentation of the FileSystemObject.

Now, you may be wondering why one would choose a text file approach over a database approach. Well, first off, you wouldn't choose an anti-database approach and a pro-text file approach. Rather, a wise developer would use text files to complement their databases. Sometimes databases are too cumbersome and slow to use for what we need to do. If this is the case, use a text file! There is a great article on ASP101.com that discusses this: In a World Of Databases, ASP and Text Files.

Another approach to using text files is to create an HTML-based "template." Ryan S. authored a great article on this interesting technique which makes use of the FileSystemObject in an article entitled Using Template Files to Create Dynamic ASP Pages.

There are many situations where text files are better suited for use over databases. The secret is to find these key times and implement the text file solution. Now, before I go, let me throw you an interesting idea: using text files as database files!! You can use ADO to connect to Comma-Delimited files. These are just text files where each column is separated by a comma, and each row is separated by a newline character. Using the FileSystemObject (FSO) you could, in theory, create tables on the fly, alter tables and such, using FSO and/or ADO. For more information on using Comma-delimited files as database tables, read Abd Shomad's article Connecting to Text-Delimited Database Files on the Fly.

Happy Programming!

FAQ Table of Contents   Using Cookies Rotating Banners 


ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article