Common ASP References โ VBScript, Server Objects, File APIs & Helpers
Introduction โ Build Efficient Classic ASP Apps with Reusable Helpers
Classic ASP comes equipped with a powerful set of built-in functions, objects, and APIs that make dynamic web development possible. From handling file systems and errors to rotating ads and detecting browsers, these shared references form the backbone of many classic web applications.
In this guide, youโll learn:
- Frequently used VBScript functions and keywords in ASP
- How to use
Request,Response, andServerobjects - How to manage files using the FileSystemObject API
- How to handle errors and work with dictionaries
- How to rotate content and ads dynamically
Topics Covered
| Topic | Description |
|---|---|
| ASP โ VB Functions | Commonly used VBScript functions for string, math, and date handling |
| ASP โ VB Keywords | Reserved words and syntax used in Classic ASP scripting |
| ASP โ Response / Request | Read inputs and send output to browser |
| ASP โ Server Object | Access file system, components, pathing, and encoding |
| ASP โ Error Handling | Use On Error Resume Next and Err object |
| ASP โ File System API (Files/Folders) | Read, write, delete files or folders on the server |
| ASP โ File System API (Drive/TextStream) | Inspect drives, read/write text files |
| ASP โ Dictionary Object | Store key-value pairs in memory like a hashtable |
| ASP โ Ad Rotator | Rotate banner ads from XML or text file |
| ASP โ BrowserCap | Detect browser type and capabilities |
| ASP โ Content Linking | Create navigable, linked content dynamically |
| ASP โ Content Rotator | Show different text/images on each page load |
ASP โ VB Functions
Commonly used VBScript functions in Classic ASP:
| Function | Use Case |
|---|---|
Len() | Get string length |
Trim() | Remove extra spaces |
Now() | Current date and time |
DateAdd() | Add intervals to dates |
UCase() | Convert string to uppercase |
IsEmpty() | Check if variable is uninitialized |
Example:
<%
Response.Write UCase("hello")
%>
ASP โ VB Keywords
Key reserved words in VBScript for control flow and logic:
If,Then,Else,End IfSelect Case,CaseFor,Next,Do,While,LoopFunction,Sub,CallDim,Set,Const
Must avoid using them as variable names.
ASP โ Request / Response Objects
Read Input:
name = Request.Form("name")
Write Output:
Response.Write "Welcome " & name
Response can also handle headers:
Response.AddHeader "Content-Type", "text/plain"
ASP โ Server Object
Access server resources:
Set fs = Server.CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("data.txt")
encoded = Server.HTMLEncode("<b>bold</b>")
CreateObject, MapPath, URLEncode, HTMLEncode are commonly used.
ASP โ Error Handling
On Error Resume Next
Set conn = Nothing
If Err.Number <> 0 Then
Response.Write "Error: " & Err.Description
Err.Clear
End If
Always clear the error after handling it.
ASP โ File System API (FileSystemObject)
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile(Server.MapPath("data.txt"), 1)
text = file.ReadAll
file.Close
File Modes:
1= Read2= Write8= Append
ASP โ File System API (Drive/TextStream)
Set d = fs.GetDrive("C:")
Response.Write "Free space: " & d.FreeSpace
Set txt = fs.CreateTextFile(Server.MapPath("log.txt"), True)
txt.WriteLine "Log entry"
txt.Close
Can inspect drives and log diagnostics.
ASP โ Dictionary Object
Set dict = Server.CreateObject("Scripting.Dictionary")
dict.Add "name", "Alice"
Response.Write dict.Item("name")
Use .Exists, .Remove, .RemoveAll for management.
ASP โ Ad Rotator
<!--#include file="adrotator.inc"-->
<%
Randomize
DisplayAd "ads.txt"
%>
ads.txt should list banners with descriptions and links.
ASP โ BrowserCap
browser = Request.ServerVariables("HTTP_USER_AGENT")
Response.Write browser
Or use BrowserCap.ini for advanced browser detection (requires config).
ASP โ Content Linking
link = "page.asp?id=" & articleID
Response.Write "<a href='" & link & "'>Read More</a>"
Use QueryString values to build navigation and filters.
ASP โ Content Rotator
Simple content switcher:
contentList = Array("Welcome!", "Hello!", "Thanks for visiting.")
Randomize
i = Int((UBound(contentList) + 1) * Rnd)
Response.Write contentList(i)
Great for rotating tips, quotes, or headlines.
Summary โ Recap & Next Steps
Classic ASP offers a rich toolkit of built-in functions and objects that streamline file handling, user input, error management, and dynamic output. These reusable helpers are key to building and maintaining robust legacy web apps.
Key Takeaways:
- VBScript functions simplify strings, dates, and math operations
Request,Response, andServerare the core I/O interfaces- FileSystemObject allows server-side file and folder manipulation
- Dictionary, Ad Rotator, and BrowserCap add flexibility to UIs
Real-World Applications:
- File upload logging and email forms
- Banner ad rotation for monetization
- Form field validation with VBScript
- Session-aware UI logic and page includes
Frequently Asked Questions
What is the FileSystemObject in ASP?
It allows you to read, write, delete, and inspect files and directories on the server.
How do I handle errors gracefully in Classic ASP?
Use On Error Resume Next, then check Err.Number and Err.Description.
Can I use dictionaries in Classic ASP like hashtables?
Yes, using Scripting.Dictionary.
Whatโs the purpose of Server.MapPath?
Converts virtual paths to physical server paths (e.g., "/data.txt" โ "C:\inetpub\...").
Share Now :
