Amazon.com: PC Books || Educational Software || Magazines
Amazon: Books-CA || Software-CA || Books-UK || Software-UK

HTML | Javascript | ASP | PHP | VBScript | SQL | Hardware | PC FAQ| WinXP|

Learn to Build, Upgrade, or Repair your Computer Ebook + PC Safety 101 kwwebservice.com Reasonably priced web development & hosting
ASP Basics
Introduction
Variables & Arrays
Sub & Functions
If Statements
Case Statements
Loop Statements
Date Objects
Form Processing
Text File Objects
Database Access
Adding Record
Updating Record
Deleting Record
Virtual Includes
Cookies
Server Variables
Creating Login Page
E-mail
ASP Books @
CA Amazon
UK Amazon
US Amazon

  :: Home
PC Topics
  :: Build A PC
  :: Windows XP
  :: PC Help
Tutorials
  :: HTML
  :: JavaScript
  :: ASP
  :: PHP
  :: VBScript
  :: SQL
Miscellaneous
  :: Code/Scripts
  :: Forum
  :: Links
  :: Contact us
  :: Tell A Friend
  :: In Somali
  ::
Web Articles
  Top Web Hosting
Reviews
  Processing
Online Card Payment Guide
  Domain name
registration & buying guide
  Getting
a website online guide
  Search Engine
submission & optimization tips
Netfirms Web Hosting
Free trial
Quality business correspondence.
Yahoo! Search Marketing

Writing to a Text File using ASP

You can write to or read from a text file using ASP.  The following is simple example that illustrates how to create text file and write some information to it.
<html>
<title>Create txt file </title>
<body>
<%
Set fileObj=Server.CreateObject("Scripting.FileSystemObject")
set file1=fileObj.CreateTextFile("\asp\TextFile.txt")
file1.WriteLine("This is what goes to the text file that would be created")
file1.WriteLine("This is the second line of the text file")
file1.Close
set file1=nothing
set fileObj=nothing
%>
</body>
</html>
Set fileObj=Server.CreateObject("Scripting.FileSystemObject") creates the instance of the file object.   set file1=fileObj.CreateTextFile("\asp\TextFile.txt") creates the actual file, TextFile.txt within the specified path. WriteLine() writes the quoted line of text then we close the file and set instance back to nothing.

Reading from a Text File

Reading from a text file is also very easy and similar to writing to it.  The following example illustrates how to read from a text file.
<html>
<body>
<%
Set fileObj=Server.CreateObject("Scripting.FileSystemObject")
Set listFile=fileObj.OpenTextFile(Server.MapPath("\cliktoprogram\asp\list.txt"), 1)
do while listFile.AtEndOfStream = false
Response.Write(listFile.ReadLine)
Response.Write("<br>")
loop
listFile.Close
Set listFile=Nothing
Set fileObj=Nothing
%>
</body>
</html>
This example displays all the lines of the text file one by one. To display all the lines at once without line breaks, simply replace the lines starting with do while and ending with loop to Response.Write(listFile.ReadAll).
  • To display the first line of the text file use, Response.Write(listFile.ReadLine).
  • To skip line of a text file use,listFile.SkipLine
  • To skip part of line of a text use,listFile.Skip(2).  This will skip 2 characters.
  • To write an empty line use, WriteBlankLines
  • Also you can assign the line to a variable like this,text=listFile.ReadLine
Form Processing Database access
Bluehost.com Web Hosting $6.95
PC System Tools
SpyCleaner
Registry Mechanic
4Diskclean Pro
Health PC Club
TweakNow
Registry Washer
SpyAnyWhere
System Lifeguard
...More/Details

PC Articles
  Computer Safety
prevent viruses & Spyware