Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Active Server Pages (ASP) is a server side scripting language that lets a webmaster transform the plain, static web site into a dazzling, dynamic solution. With Microsoft's server side scripting language you can gather data from your site's visitors, use sessions, cookies, application variables, and more. Don't worry if you don't know what all of those terms mean because you will soon be learning all about them.
Installing ASP
ASP (Active Server Pages) is part of the Internet Information Server (IIS) package that comes with certain Microsoft operating systems. Currently there is no native support for ASP on the other operating systems, such as: Mac OS, Linux, and Unix. The operating systems that do have the ability to support ASP are: Windows 95, 98, NT, 2000, 2003, XP Pro. You will notice that XP Home Edition was not on the list of operating systems, and this was done intentionally by Microsoft to encourage people to purchase the more expensive XP Professional Edition. This lesson will provide an installation walkthrough for Windows 98 and Windows XP Pro. Note: Chilisoft does have a solution for some Linux and Solaris users and can be purchased at Sun's web site: Sun Java System Active Server Pages 4.0.
8. If IIS was install appropriately you should be taken to the welcome screen http://localhost/localstart.asp
Tizag's Setup
This tutorial was written on XP Professional, but any of you using Windows 98 or other Windows derivatives should have no problem following along. If you do encounter a specific problem, please feel free to Contact Us.
Inside the wwwroot folder create a New Folder and rename it "tizagASP" To access this directory you would type the following into Internet Explorer: o http://localhost/tizagASP/FILENAME.asp Where FILENAME is name of your ASP file
All of the files you create while reading the ASP Tutorial should go into this directory.
Tips
1. Be sure to save your ASP files in a folder that exists inside C:\Inetpub\wwwroot 2. Tizag ASP Tutorial saves file to C:\Inetpub\wwwroot\tizagASP 3. Run your ASP files by using Internet Explorer and typing "http://localhost/tizagASP/FILENAME.asp" without quotes and replace FILENAME with the name of your specific ASP file
Before we get into the meat and potatoes of ASP programming let's just run a very simple ASP script to check that your IIS installation and ASP are working properly. Open up a text editor and type the following ASP Code and save the file as "firstscript.asp".
Be sure to save this file to the directory "tizagASP" as was mentioned in the previous lesson, Running ASP. Launch Internet Explorer and type the following into the address bar:
http://localhost/tizagASP/firstscript.asp
ASP Syntax
If you have any experience with PHP, Javascript, or general programming then ASP's syntax will make some sense to you. However, if you only have experience with web technologies like HTML and CSS, then ASP will be more of a challenge.
ASP Code:
<html> <body> <% Response.Write("Hello Me") %> </body> </html>
ASP - Tags
These special tags <% and %> will always encapsulate your ASP code. Some things about the ASP tag that sets it apart from normal HTML tags: 1. An opening ASP tag is <% while an HTML tag normally looks like <tagname> 2. A closing ASP tag looks like %> while an HTML tag normally looks like </tagname> 3. ASP code can occurr anywhere, even within an HTML tag opening tag like this:
ASP Code:
<a href="<% Response.Write("index.asp") %>">Home</a>
Display:
Home
Display:
The date is: 9/28/2011 If you already know VBScript or Visual Basic programming then you'll recognize Dim as Dimension, which is used to "dimension" variables. It is a good programming practice to "dimension" all your variables before you use them, as we did with myString in the above example. Now that we have our ASP Code working, say that we wanted to use our ASP code along with some client side Javascript code. To keep it simple we are just going to use the Javascript write function and have our ASP
Code fill in the Date. All the Javascript client code is in the default color, but ASP Server Side Code is in Red.
Display:
The date is: 9/28/2011 If you just want to program in ASP you can disregard the above example if you find it confusing. Just remember that you can have client-side Javascript code and server-side ASP/VBScript code included in an ASP generated web page!
ASP Code:
<%@ Language="javascript" 'The rest of your ASP Code....%>
Remember, if this isn't your first line of ASP code then everything will break.
Learning Javascript
If you don't already know javascript very well, then it is probably a good idea if you just learn VBScript instead of trying to get ASP to work with javascript. I have heard of many fellows having trouble getting ASP to cooperate properly with Javascript and there just isn't that many informative examples of programming ASP with Javascript available. Your ASP career will be much more pleasant if you simply stick with VBScript from the get go.
ASP Operators
ASP is programmed in VBScript by default, thus ASP's operators are VBScript operators by default. Operators in ASP fall into four categories Math, Comparisons, the somewhat more advanced Logic operators, and Leftovers(those that don't fit well into any category).
Comparison Operators
Comparison operators are used when you want to compare two values to make a decision. Comparison operators are most commonly used in conjunction with "If...Then" and "While something is true do this..." statements, otherwise known as conditional statements. The items that are most often compared are numbers. The result of a comparison operator is either TRUE or FALSE. Operator = < > <= >= <> Example Result Equal To 4=3 False Less Than 4<3 False Greater Than 4>3 True Less Than Or Equal To 4 <= 3 False Greater Than Or Equal To 4 >= 3 True Not Equal To 4 <>3 True English
Logical Operators
The above comparison operators result in a truth value of TRUE or FALSE. A logical operator is used for complex statements that must make decisions based on one or more of these truth values. Operator English Example Result And Both Must be TRUE True and False False
Or Not
One Must be TRUE True or False Flips Truth Value Not True
True False
String Operators
The only string operator is the string concatenation operator "&" that takes two strings and slams them together to form a new string. An example would be string1 = "Tim" and string2 = " is a Hero". The following code would combine these two strings into one: string3 = string1 & string2 Operator English Example Result & String Concatenation string4 = "Bob" & " runs" string4 = "Bob runs" We will be using these operators throughout the tutorial, so chances are you will get understand them more and more as this tutorial goes on.
ASP - If Statement
An If Statement is used to make a decision in your ASP program to execute certain code if some condition is True. Because ASP is programmed in VBScript by default, when you program an ASP If Statement it is actually the same as programming a VBScript If Statement.
If Statement Syntax
ASP's If Statement is slightly different than the If Statement implementation in most other languages. There are no brackets, or curly braces, nor are there any parenthesis. Rather the beginning of the code to be executed in the If Statement when its true is marked with Then and the end of the If Statement is plainly marked with End If. Below is a very basic If Statement that will always be True.
ASP Code:
<% Dim myNum myNum = 6 If myNum = 6 Then Response.Write("Variable myNum = 6") End If %>
Display:
Variable myNum = 6 You might notice that the "=" operator is used to both set the value of myNum to 6 at first, then it is used to compare myNum to 6 in our If Statement. This dual use of the equals operator is confusing to many, but it might help you to remember that in ASP you cannot set the value of variables within If Statements, which means that the "=" can only compare!
Sometimes you might want to execute some code both when the If Statement is True and some different code when it is False. Just like other programming languages, you can do this in ASP with the use of the Else keyword. Below is an example that will always be false, so that the Else portion of the If Statement is always executed.
ASP Code:
<% Dim myNum myNum = 23 If myNum = 6 Then Response.Write("Variable myNum = 6") Else Response.Write("**Variable myNum = " & myNum) End If %>
Display:
**Variable myNum = 23
ASP Code:
<% Dim myFastfood myFastfood = "JBox" If myFastfood = "McD's" Then Response.Write("Happy Meal Por Favor!") ElseIf myFastfood = "JBox" Then Response.Write("Two tacos please!") Else Response.Write("Foot-long turkey sub.") End If %>
Display:
Two tacos please!
ASP Code:
<% Dim myNum myNum = 5 Select Case myNum Case 2 Response.Write("myNum Case 3 Response.Write("myNum Case 5 Response.Write("myNum Case Else Response.Write("myNum End Select %>
Display:
myNum is Five
ASP Code:
<% Dim myNum myNum = 454 Select Case myNum Case 2 Response.Write("myNum Case 3 Response.Write("myNum Case 5 Response.Write("myNum Case Else Response.Write("myNum End Select %>
Display:
myNum is 454
So far we have only used integers in our Select Case statements, but you can also use a string as the variable to be used in the statement. Below we Select against a string.
ASP Code:
<% Dim myPet myPet = "cat" Select Case myPet Case "dog" Response.Write("I own a dog") Case "cat" Response.Write("I do not own a cat") Case Else Response.Write("I once had a cute goldfish") End Select %>
Display:
I do not own a cat
ASP Code:
<% 'Single Variable Declarations Dim myVar1 Dim myVar2 'Multiple Variable Declarations Dim myVar6, myVar7, myVar8 %>
1. 2. 3. 4.
Variable name must start with an alphabetic character (A through Z or a through z) Variables cannot contain a period Variables cannot be longer than 255 characters (don't think that'll be a problem!) Variables must be unique in the scope in which it is declared (Basically, don't declare the same variable name in one script and you will be OK).
ASP Code:
<% 'Single Variable Declarations Dim myString, myNum, myGarbage myNum = 25 myString = "Hello" myGarbage = 99 myGarbage = "I changed my variable" Response.Write("myNum = " & myNum & "<br />") Response.Write("myString = " & myString & "<br />") Response.Write("myGarbage = " & myGarbage & "<br />") %>
Display:
myNum = 25 myString = Hello myGarbage = I changed my variable
ASP Arrays
Arrays in ASP follow the exact same form and rules as those arrays in VBScript. You can create an array of specific size or you can create a dynamic sized array. Below we have examples of both types of arrays.
ASP Code:
<% Dim myFixedArray(3) 'Fixed size array Dim myDynArray() 'Dynamic size array %> We are going to focus on fixed size arrays first and cover dynamic arrays later on in this lesson.
The name of the array The value you want to store The position in the array where you want to store the value.
An array is a group of variables that you can access by specifying the position inside the array. Our array myFixedArray has four positions: 0, 1, 2 and 3. Let's assign some values to our array.
ASP Code:
<% Dim myFixedArray(3) 'Fixed size array myFixedArray(0) = "Albert Einstein" myFixedArray(1) = "Mother Teresa" myFixedArray(2) = "Bill Gates" myFixedArray(3) = "Martin Luther King Jr." %>
ASP Code:
<% Dim myFixedArray(3) 'Fixed size array myFixedArray(0) = "Albert Einstein" myFixedArray(1) = "Mother Teresa" myFixedArray(2) = "Bill Gates" myFixedArray(3) = "Martin Luther King Jr." For Each item In myFixedArray Response.Write(item & "<br />") Next %>
Display:
Albert Einstein Mother Teresa Bill Gates Martin Luther King Jr.
ASP Code:
<% Dim myDynArray() 'Dynamic size array ReDim myDynArray(1) myDynArray(0) = "Albert Einstein" myDynArray(1) = "Mother Teresa" ReDim Preserve myDynArray(3) myDynArray(2) = "Bill Gates" myDynArray(3) = "Martin Luther King Jr." For Each item In myDynArray Response.Write(item & "<br />") Next %>
Display:
Albert Einstein Mother Teresa Bill Gates Martin Luther King Jr.
ASP Session
The Session Object in ASP is a great tool for the modern web site. It allows you to keep information specific to each of your site's visitors. Information like username, shopping cart, and location can be stored for the life of the session so you don't have to worry about passing information page to page. In old web page designs you might have to try to pass information this information through HTML Forms or other methods.
ASP Code:
<% 'Start the session and store information Session("TimeVisited") = Time() Response.Write("You visited this site at: " & Session("TimeVisited")) %>
Display:
You visited this site at: 10:47:14 PM Here we are creating two things actually: a key and a value. Above we created the key "TimeVisited" which we assigned the value returned by the Time() function. Whenever you create a Session Variable to be stored in the Session Contents collection you will need to make this Key / Value pair.
ASP Session ID
The ASP Session ID is the unique identifier that is automatically created when a Session starts for a given visitor. The Session ID is a property of the Session Object and is rightly called the SessionID property. Below we store the user's SessionID into a variable.
ASP Code:
<% Dim mySessionID
ASP Code:
<% Session.Timeout = 240 Response.Write("The timeout is: " & Session.Timeout) %>
Display:
The timeout is: 240 Note: Timeout is defined in terms of minutes.
ASP Cookies
Like ASP Sessions, ASP Cookies are used to store information specific to a visitor of your website. This cookie is stored to the user's computer for an extended amount of time. If you set the expiration date of the cookie for some day in the future it will remain their until that day unless manually deleted by the user. If you have read through the Sessions lesson you will notice that ASP Cookies code has several similarities with ASP Sessions.
ASP Code:
<% 'create the cookie Response.Cookies("brownies") = 13 %>
Now that we've created this cookie, how do we get that information back from the user's computer?
ASP Code:
<% Dim myBrownie 'get the cookie myBrownie = Request.Cookies("brownies") Response.Write("You ate " & myBrownie & " brownies") %>
Display:
You ate 13 brownies Note: Be sure you see that when you create a cookie you use Response.Cookies, but when you retrieve a cookie you use Request.Cookies.
ASP Code:
<% 'create a 10-day cookie Response.Cookies("brownies") = 13 Response.Cookies("brownies").Expires = Date() + 10 'create a static date cookie Response.Cookies("name") = "Suzy Q." Response.Cookies("name").Expires = #January 1,2009# %>
ASP Code:
<% 'create a big cookie Response.Cookies("brownies")("numberEaten") = 13 Response.Cookies("brownies")("eater") = "George" Response.Cookies("brownies")("weight") = 400 %>
ASP Code:
<% For Each key In Request.Cookies("Brownies") Response.Write("<br />" & key & " = " & _ Request.Cookies("Brownies")(key)) Next Response.Cookies("brownies")("numberEaten") = 13 Response.Cookies("brownies")("eater") = "George" Response.Cookies("brownies")("weight") = 400 %>
Display:
numberEaten = 13 eater = George weight = 400
ASP Strings
This lesson will tell you how to use strings in ASP. VBScript is the default scripting language for ASP, so if you know VBScript strings inside and out you will already know everything you're about to read!
ASP Code:
<% Dim myString myString = "Hello There!" %>
ASP Code:
<%
Dim fname, lname, name fname = "Teddy" lname = " Lee" name = fname & lname Response.Write("Hello my name is " & name) %>
Display:
Hello my name is Teddy Lee
ASP Code:
<% Dim fname, myAge, myHeightM, allOfIt myAge = 7 myAge = myAge & 5 myHeightM = 2 fname = "Teddy" allOfIt = fname & " is " & myAge & " years old and " allOfIt = allOfIt & myHeightM & " meters tall" Response.Write(allOfIt) %>
Display:
Teddy is 75 years old and 2 meters tall
ASP Code:
<% Dim myStringDate, myTrueDate myStringDate = "August 18, 1920" If IsDate(myStringDate) Then myTrueDate = CDate(myStringDate) Response.Write(myTrueDate) Else Response.Write("Bad date formatting!") End If %>
Display:
8/18/1920 Our string myStringDate was a properly formatted date and was successfully converted and written to the browser.
ASP Forms
With ASP you can process information gathered by an HTML form and use ASP code to make decisions based off this information to create dynamic web pages. An ecommerce site could take the user's information and store it into a database named Customers. This information could then be used to prepopulate the shipping information when the customer is ordering another product. A forum might save the user's post to a forum by taking the title and body and saving it to a file so that it can then be called later when someone wants to view it.
tizagForm.html Code:
<form method="GET" action="tizagGet.asp"> Name <input type="text" name="Name"/> Age <input type="text" name="Age"/> <input type="submit" /> </form>
tizagForm.html Code:
<form method="GET" action="tizagGet.asp"> Name <input type="text" name="Name"/> Age <input type="text" name="Age"/> <input type="submit" /> </form>
Now we need to create our ASP web page "tizagGet.asp" that will process this data.
tizagGet.asp Code:
<% Dim name, age name = Request.QueryString("Name") age = Request.QueryString("Age") Response.Write("Name: " & name & "<br />") Response.Write("Age: " & age & "<br />") %>
tizagGet.asp Result:
Name: Fred Age: 52
tizagPost.asp Code:
<% Dim name, age name = Request.Form("Name") age = Request.Form("Age") Response.Write("Name: " & name & "<br />") Response.Write("Age: " & age & "<br />") %>
tizagPost.asp Result:
Name: Jack Age: 15
Our HTML file will be called "tizagEmailForm.html" and should be saved in a directory that can Run ASP.
tizagEmailForm.html Code:
<form method="POST" action="tizagEmail.asp"> To <input type="text" name="To"/> <br /> From <input type="text" name="From"/> <br /> Subject <input type="text" name="Subject"/> <br /> Body <textarea name="Body" rows="5" cols="20" wrap="physical" > </textarea> <input type="submit" /> </form>
If you would like a refresher on HTML Forms check out our HTML Forms Lesson.
tizagEmail.asp:
<% 'Sends an email Dim mail Set mail = Server.CreateObject("CDO.Message") mail.To = Request.Form("To") mail.From = Request.Form("From") mail.Subject = Request.Form("Subject") mail.TextBody = Request.Form("Body") mail.Send() Response.Write("Mail Sent!") 'Destroy the mail object! Set mail = nothing %>
Please note that this is a very basic ASP Email Form and is only for education purposes. If you were to put an email form on your web site you would want to do some checking to make sure the email addresses are valid, allow for attachments, etc.
ASP Object
Objects are a way of encapsulating multiple methods (they're like functions) and variables in one easy to manage Uber-Variable (an Object). Objects in ASP resemble other Object Oriented Programming languages. In this lesson we will be using the ASP CDO.Message object as our example object to be dissected.
ASP Code:
<% Dim myObject Set myObject = Server.CreateObject("CDO.Message") 'You must Set your objects to "nothing" to free up the 'the computer memory that was allocated to it Set myObject = nothing %>
That wasn't too painful, was it? Let's cover some more bases on the object model. Objects are a collection of related things that are combined into this blob of programming goo that can be created and destroyed whenever we may need it. For example say that you wanted to make an object that allowed you to send an email... Well there are certain things all emails have: To, From, CC, Subject, etc. This list of variables that are common to every email would be quite tiresome to have to create for every email we sent. Wouldn't it be nice if we could create some sort of Uber-Variable(Object) that would group all these smaller variables into one thing?
objectName.propertyName = someValue
In this tiny example below we are creating a new mail object and setting its To and From properties.
ASP Code:
<% Dim myObject Set myObject = Server.CreateObject("CDO.Message") 'Then we set the To and From properties myObject.To = "little.timmy@example.com" myObject.From = "huge.jill@example.com" 'You must Set your objects to "nothing" to free up the 'the computer memory that was allocated to it Set myObject = nothing %>
Now I know we didn't DO anything in the above example, but we still need to learn a bit more about objects before we can get anything done! Objects, besides having a clump of associated common variables, may also have a collection of functions(which become referred to as methods) associated with them. These methods are processes that you would want to commonly do to either manipulate the variables of the object or to use the variables to do something. In our Message object we have a collection of information that, when put together into the proper email form and sent to an email service will become an email. All this complex code has been programmed by Microsoft employees and stored into the Message objects Send method.
ASP Code:
<% Dim myObject Set myObject = Server.CreateObject("CDO.Message") 'Then we set the To and From properties myObject.To = "little.timmy@example.com" myObject.From = "huge.jill@example.com" myObject.Subject = "Can you see me?" myObject.TextBody = "I'm really really big!" myObject.Send() 'You must Set your objects to "nothing" to free up the 'the computer memory that was allocated to it Set myObject = nothing %>
Note:If you are running this on your home computer there are a slough of issues that may arise with sending an email. Microsoft has a large FAQ about using the CDO.Message object that may help you. Knowing Microsoft, that link may go dead soon, so Contact Us if it expires!
ASP Components
An ASP Server Component is a collection of code that has been made by Microsoft (advanced users can also create their own components), and included in IIS. With the use of ASP you can unlock the power of this premade code. These objects can be used to do a ton of things, such as: an easy-to-use ad rotation service, an interface to a database, a means of manipulating files and much more.
Display:
Current folder is: tizagASP
Finishing Up
The last thing on our to-do list is to get access to the names of the files in our working directory. The Folder object contains a method that returns a collection of all the files in the current directory. The code for accessing this collection and displaying the filenames is in the example below.
If you have done every example in this ASP Tutorial your web page produced would look like this. Notice that the files are automatically sorted alphabetically!
Display:
firtscript.asp tizagComponent.asp tizagEmail.asp tizagForm.html tizagGet.asp tizagPost.asp
ASP Comments
As we have stated way too many times now, ASP uses VBScript as its default programming language. This means VBScript comments are ASP comments. It's a darn shame too because that means there isn't any support for multiple line comments that you see in HTML and various other programming languages.
ASP Code:
<% 'Hello I am a comment
In the above example we had two comments. The first comment was a note style comment. Programmers often use these kinds of comments to leave information to people who are going to read their code or to themselves. The second comment we created commented out "Dim oldVar1, oldVar2" preventing the ASP interpreter from reading this line of code. This kind of comment is a block-out comment that is often used to temporarily remove code from a file that may be causing errors or is just unnecessary at the time.
ASP Code:
<% Dim newVar1, newVar2 newVar = "Hello. 'I am not commented out" %>
That's pretty ugly and confusing to look at, so let's get right in to the details of each of the symbols and see what they mean.
ASP Code:
<% Dim myString myString = "One String" myString = myString & " another string" Response.Write(myString) %>
Display:
One String another string
ASP Code:
<% 'This is a comment. %>
ASP Code:
<% Response.Write("This is probably the longest "&_ "string to be typed out on this page and maybe "&_ "even this whole tutorial on ASP!!!") %>
Display:
This is probably the longest string to be typed out on this page and maybe even this whole tutorial on ASP!!!
ASP Code:
<% Dim Dim Dim x=3 %> x y z : y=25 : z=x-y : y=x*z : z=x*x-z+y : y=5*3*z*2/x
ASP allows for Object Oriented Programming and these objects have methods that can only be called by first stating the object, then placing a period and finally calling the method by its name. The form for using the period is:
myObject.MethodName()
If you would like to learn more about ASP objects see our ASP Object Lesson.
ASP Code:
<html> <body> <% 'My ASP code goes here. %> </body> </html>
ASP Code:
<%=2%> <br /> <%="Hello"%> <br /> <%=Date()%>
Display:
2 Hello 9/28/2011
Registering a DLL
Before you can start using the code that resides in the DLL file, you must first register the DLL with the windows runtime library. There are two ways to let windows know about this new DLL.
or
The first option is self-explanatory, but the second option takes a bit more work. Here is a quick How-To on registering DLLs: 1. Find out the location of your DLL. We will be using C:\Inetpub\wwwroot\tizagASP\myDLL.dll in this example. 2. Click on the Start menu and choose Run 3. Type in regsvr32.exe "C:\Inetpub\wwwroot\tizagASP\myDLL.dll" (With the quotes) 4. You should get a confirmation message if it succeeded, such as: "DllRegisterServer in C:\Inetpub\wwwroot\tizagASP\myDLL.dll succeeded"
ASP Code:
<% 'Note this is example code, it will not work ' unless you create a myDLL, myClass, and a myMethod Dim myObject myObject = Server.CreateObject("myDLL.myClass") myObject.myMethod("something") myObject = nothing %>
ASP ADO
This lesson will provide a brief overview of what ADO is and why it is necessary to have in your ASP programming repertoire. ADO stands for ActiveX Data Objects. ActiveX Data Objects are a collection of components that can be used in your ASP programs.
Before you can connect to the Access database you have to first create the Access database file. Fire up your copy of MS Access and create the following database: 1. Create a New blank database called "tizag.mdb" (without the quotes) and save it to "C:\Inetpub\wwwroot\tizagASP\" (without the quotes) 2. Use the wizard to create the database. 3. Add two fields to your table: FirstName and LastName 4. Click Next 5. Name the table "TizagTable" (without the quotes) 6. Select "Yes, set a primary key for me" 7. Click Next 8. Click Finish Now that we have our database all that remains to connect to it.
ASP Code:
<% Dim myConn Set myConn = Server.CreateObject("ADODB.Connection") myConn.Open = ("DRIVER={Microsoft Access" &_ " Driver (*.mdb)};DBQ=" &_ "C:\Inetpub\wwwroot\tizagASP\tizag.mdb;") myConn.Close() Set myConn = nothing %>
ASP vs PHP
Here at Tizag.com we teach two ways to program dynamic web pages: ASP and PHP. Which one is right for you? Which one should you spend your precious time and resources learning? This lesson will talk about the benefits and drawbacks of both of these technologies and try to give you the direction you need for choosing one technology over the other.
Compared to ASP, PHP is very easy to pick up and learn a little at a time. PHP is an ideal language for the weekend or hobbyist programmer. Seems like all green pastures in the land of PHP. However, businesses do not readily embrace PHP for many reasons. A great deal of companies are running operating systems such as Windows Server 2003 or one of the Window NTs, which have been optimized to run Microsoft's proprietary language ASP. Companies usually are reluctant to switch technologies when they already have a history with one type of technology. Such a transition requires retraining or even retraining much of their staff.
ASP Files
All file interactions in ASP are done through the File System Component that is included with IIS. It includes many objects that give you a window into your system's file system. Some of the more important objects include: 1. File System Object 2. File Object 3. Folder Object Before you can gain access the second and third objects we listed above you must create the grand daddy master File System Object (FSO). Through this overarching object, everything in the File System Component can be accessed.
ASP Code:
<% Dim myFSO Set myFSO = Server.CreateObject _ ("Scripting.FileSystemObject") Set myFSO = nothing %>
ASP Code:
<% Dim myFSO, myFO Set myFSO = Server.CreateObject _ ("Scripting.FileSystemObject") Set myFO = myFSO.GetFile _ ("C:\Inetpub\wwwroot\tizagASP\firstscript.asp") Response.Write("The filename is: " & myFO.Name) Set myFO = nothing Set myFSO = nothing %>
Display:
The filename is: firstscript.asp
ASP Code:
<% Dim myFSO, myFolderO
Set myFSO = Server.CreateObject("Scripting.FileSystemObject") Set myFolderO = _ myFSO.GetFolder("C:\Inetpub\wwwroot\tizagASP") Response.Write("Current folder is: " & myFolderO.Name) For Each fileItem In myFolderO.Files Response.Write("<br />" & fileItem.Name) Next Set myFolderO = nothing Set myFSO = nothing %>
If you have been following along with this tutorial start to finish your browser will display something like this when you execute the script.
Display:
The filename is: tizagASP firtscript.asp tizag.mdb tizagComponent.asp tizagEmail.asp tizagForm.html tizagGet.asp tizagPost.asp That's all we have for files in ASP for the time being. Look for a full coverage of ASP Files in the near future.
ASP Dates
This lesson will teach you how to use the ASP Date Function, how to convert an ASP Date to a String and how to format an ASP Date.
ASP Code:
<% Response.Write(Date()) %>
Display:
9/28/2011 You can even use some shorthand techniques to make printing out the current date to your web page only one line of ASP Code. See our ASP Special Characters Lesson for more information.
ASP Code:
<%=Date%>
Display:
9/28/2011 Pretty sweet.
FormatDateTime Function
The Format Date Time function takes two arguments: a date and (optional) an integer from 0 through 4. The meanings of these numbers are as follows:
0 - This is the default setting. A short date DD/MM/YYYY will be used. 1 - A long date defined by the computer's regional settings. 2 - A short date defined by the regional settings. 3 - (time)A time using the time format defined by the regional settings. 4 - (time)A time using military time HH:MM (H = hour, M = Minute)
ASP Code:
<% Response.Write("0 = Response.Write("<br Response.Write("<br Response.Write("<br Response.Write("<br %> " & />1 />2 />3 />4 FormatDateTime(Date, 0)) = " & FormatDateTime(Date, = " & FormatDateTime(Date, = " & FormatDateTime(Date, = " & FormatDateTime(Date, 1)) 2)) 3)) 4))
Display:
0 = 9/28/2011 1 = Friday, October 21, 2005 2 = 9/28/2011 3 = 12:00:00 AM 4 = 00:00 You'll notice that the last two options are pretty worthless if you are just working with a standard date, but they are useful for formatting ASP's Time.
If you are looking for a web host that supplies both support for ASP and for SQL, amongst other things, then check out our list of hosts we have gathered up. The list is broken up into three classes: Personal, Business, and Expensive Custom Solutions.
FreeSQL - This web site allows developers to practice their SQL for free. This is not a web host. DiscountASP.net - Cheap SQL Hosting. This is a shared web hosting environment.
Fortune City - Extra features for small businesses. Aschosting - 24 hour toll free emergency support line.
ICO - Dedicated Server Solutions. The Planet - Another option for a dedicated solution.
FreeSQL - This web site allows developers to practice their SQL for free. This is not a web host. Think Host - Cheap MySQL Hosting. This is a shared web hosting environment.
ASP Manual(s)
On this page we have collected a bunch of useful sites that provide a manual to ASP and VBScript, the language that you program ASP in by default. This page itself is not a manual. ASP is proprietary software of Microsoft and so we have split up information into Microsoft and Non-Microsoft related resources.
Microsoft
MSDN ASP Tutorial - Microsoft's ASP Tutorial under Windows 2000 Server Documentation Online. ASP to ASP.NET - This manual provides information on migrating from ASP to ASP.NET MSDN VBScript User Guide - Microsoft's VBScript User Guide. If you're going to be programming in ASP you might want to get a strong grasp of VBScript, the default language to program ASP in.
Non-Microsoft
ASPIN - ASPIN has a huge collection of resources for ASP. The only downside is the time and effort it takes to get what you want.