Some interesting server-side ActiveX components are available to the Visual InterDev developer via the Server Objects tab of the Visual InterDev 6.0 Toolbox. Figure 17-4 below shows the available components. These components address common challenges facing Web developers, such as determining the type of browser that is requesting a page, sending e-mail from within ASP code, or reading and writing text files. These components can save you many hours of development time while they increase the functionality and interactivity of your applications.
Figure 17-4. The Server Objects tab of the Visual InterDev 6.0 Toolbox showing the server objects available for use in your applications.
To access the server objects on the Toolbox, all you need to do is open a new or existing ASP Web page within the Visual InterDev environment. This will enable all of the server object icons on the Server Objects tab so that you can drag them from the Toolbox onto your Web page.
NOTE
The list of objects on the Server Objects tab is predefined. This means that the list is the same no matter what workstation or server you are on. There is a chance that a server object that is displayed on the Toolbox might not actually be installed on your server. Always be sure to test your pages to ensure they are running correctly and the relevant server objects are installed on your server. The server objects are part of the IIS 4.0 installation, so if they are missing you'll want to install them from the Windows NT 4.0 Option Pack.
When you drag an object from the Server Object tab of the Toolbox onto your ASP Web page, the editor will create an <OBJECT> block for you with the correct RUNAT and PROGID attributes. After specifying the id that you would like to use for the object, you can reference it in your script. For example, if you drag a Collaboration Data Objects for Windows NT Server (CDONTS) Library NewMail object onto your Web page, the <OBJECT> block looks like this:
<OBJECT RUNAT=server PROGID=CDONTS.NewMail id=OBJECT1></OBJECT>
First you'll want to rename the id for the NewMail object to something more meaningful, such as oNewMail:
<OBJECT RUNAT=server PROGID=CDONTS.NewMail id=oNewMail></OBJECT>
Now you can reference the NewMail object in your script, as shown here:
<% oNewMail.From = nick.evans@us.pwcglobal.com oNewMail.To = nick.evans@us.pwcglobal.com oNewMail.Subject = "CDONTS" oNewMail.Body = "This NewMail object makes sending e-mail simple!" oNewMail.Send Set oNewMail = Nothing %>
The complete ASP code for this example would look like this:
<@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <OBJECT RUNAT=server PROGID=CDONTS.NewMail id=oNewMail></OBJECT> <% oNewMail.From = nick.evans@us.pwcglobal.com oNewMail.To = nick.evans@us.pwcglobal.com oNewMail.Subject = "CDONTS" oNewMail.Body = "This NewMail object makes sending e-mail simple!" oNewMail.Send Set oNewMail = Nothing %> <P> </P> </BODY> </HTML>
In this listing, you'll notice that the <OBJECT> block lies within the HTML source code and not within the ASP script blocks. We'll be learning more about the CDONTS objects for working with e-mail later in this chapter.
Returning to the Toolbox, you'll see that the components listed on the Server Objects tab are as follows:
In addition to these components, IIS 4.0 also provides the following components that are not shown on the Toolbox but can be used nonetheless:
For more information on these additional components, please see the online Internet Information Server documentation within the Windows NT 4.0 Option Pack documentation. This documentation can be found by choosing Start|Programs|Windows NT 4.0 Option Pack|Product Documentation.
In this chapter, we'll take a look at some of the above components in greater detail. Since the ADO components have been covered in earlier chapters, and the MSMQ components have their own chapter, we'll concentrate on the following components:
Sample code for all of these components is contained on the CD-ROM under the Components Web project. There's a main page named default.htm that gives you links to all of the examples. Figure 17-5 shows the main Component Samples page.
Figure 17-5. The Component Samples page from the Components Web project on the companion CD-ROM has hyperlinks to all the code samples.