CHAPTER 16
Content Rotator Component

More often than not, the greatest challenge facing a webmaster has little to do with
the technology running her web site. The biggest challenge is providing enough
different content quickly enough so that her clients keep coming back to the site
and keep telling others about the site. Clients today have millions of sites to
choose from—often several hundred on any given subject. Why frequent yours if
the content doesn’t change often enough to make the few clicks it takes to get
there worth the effort?
One solution to this problem is to provide, on a regular basis, a small change to
your web site or its more popular pages. This small change—if clever or original
enough—can keep a user on the site just long enough for him to see something
that he may not have seen before—even if the content in question has been
present for some time. More important, for some sites this change could keep the
user long enough to notice an advertisement and click on it.
If the change is really clever, the user may frequent your site (and see your
content and view your sponsors’ advertisements) just to see that small change in
content.
Microsoft recognized this strategy as a common one and introduced an Active
Server Pages component that makes rotating HTML content on an otherwiseunchanging
document very easy. The server component is called the Content
Rotator component. This component, in conjunction with a content schedule text
file, allows you to set up a simple ASP script that retrieves a small bit of HTML.
The component then displays this HTML snippet to the client without changing
any part of your script’s other functions and without the hassle of having to switch
files on your web server in and out.
Note that this chapter documents the Content Rotator component 2.0 (Beta 3). It is
available from Microsoft at http://www.microsoft.com/windows/downloads/default.asp.
304 Chapter 16 – Content Rotator Component
Accessory Files/Required DLL Files
ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved.
Accessory Files/Required DLL Files
Controt.DLL
Controt.DLL is the dynamic link library containing the Content Rotator component.
It must be registered on the web server before it can be instantiated in your
web applications. This DLL is not installed by default when you install IIS.
Content Schedule File
The content schedule file contains HTML snippets that the Content Rotator component
retrieves and displays to the client. Each HMTL snippet is in the following
format:
%% [#uintWeight] [//Comment]
HTMLContentString
where:
%%
Signals the beginning of an HTML snippet. Each entry must begin with the
double percent sign or the Content Rotator component cannot distinguish it
from the previous snippet.
#uintWeight
A pound sign followed by an unsigned integer value (between 1 and 65,535)
that represents the relative weight of the current HTML snippet. This optional
parameter represents the relative probability that the Content Rotator component
will select this HTML snippet from the list of snippets. The actual
probability of this HTML snippet being selected by the Content Rotator
component is uintWeight divided by the total of all the snippets’ weights.
For example, assume you have three snippets with weights of 33, 34, and 33.
The first snippet would be selected 33% percent of the time, the second 34%
percent, and the third 33% of the time. If a snippet’s weight is zero, that
snippet is never chosen. The default weight is 1.
Content Rotator Summary
Properties
None
Collections
None
Methods
ChooseContent
GetAllContent
Events
None
Accessory Files/Required DLL Files 305
Content Rotator
Accessory Files/Required DLL Files
ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved.
//Comment
An optional string of comments describing the HTML snippet or its relevance.
It is for your use in maintaining the content schedule file and is never
displayed to the client. If a snippet requires more than one line of comments,
start each comment with a double percent sign (%%) followed immediately
with a double forward slash (//).
HTMLContentString
The actual HTML snippet that will be added to the client’s display. This HTML
can contain anything legal in HTML. However, you cannot have ASP script in
the HTMLContentString parameter. The Content Rotator component identifies
the beginning and end of an HTML snippet using the double percent
signs. For this reason, you can have as many lines in your HTML snippet as
you like.
The following is an example content schedule file containing five entries:
%% #33 // This identifies the first snippet of HTML.
%% // This is a second line of comments.
Click <A HREF = "http://www.movielines.com">here</A>
to learn where the following movie line originated:<BR>
<FONT SIZE = 3>"Most excellent."</FONT>
%% #5 // This is snippet two.
Click <A HREF = "http://www.horolines.com">here</A>
to learn today's horoscope.<BR>
%% #10 // This is snippet three.
This line came from a great movie:<BR>
"Humor. It is a difficult concept."
%% #27 // This is snippet four.
Comment your code; your replacement will appreciate
the work.<BR>
%% #450 // This is snippet five.
<IMG SRC="/images/coolimg.jpg">
The probabilities that each snippet in the example content schedule file will be
selected are shown in the following table:
Snippet Weight Percentage
1 33/525 6%
2 5/525 1%
3 10/525 2%
4 27/525 5%
5 450/525 86%
306 Chapter 16 – Content Rotator Component
Instantiating the Content Rotator Component
ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved.
Instantiating the Content Rotator Component
To create an object variable containing an instance of the Content Rotator component,
use the Server object’s CreateObject method. The syntax for the CreateObject
method is:
Set objMyObject = Server.CreateObject(strProgId)
where:
• The objMyObject parameter represents the name of a Content Rotator object.
• The strProgId parameter represents the programmatic ID (ProgID) for the
Content Rotator component, which is IISSample.ContentRotator.
Example
<%
' The following code uses the CreateObject method of the
' Server object to instantiate a Content Rotator object
' on the server.
Dim objContentRotator
Set objContentRotator = Server.CreateObject( _
"IISSample.ContentRotator”)
%>
For more details on the use of the CreateObject method, see its documentation in
Chapter 8, Server Object.
Comments/Troubleshooting
The Content Rotator component is very simple to use. The few problems I’ve
heard of have all stemmed from errors in the syntax of the content schedule file.
This component can be used for all sorts of “so-and-so-of-the-day” additions to
any site. Creating a “Tip of the day” for your site is a very popular use for this
component.
Methods Reference
ChooseContent
objContentRotator.ChooseContent(strContentSchedFile)
Selects an HTML snippet from the content schedule file. The snippet chosen by
the Content Rotator component is selected from all the other snippets in the
schedule file according to that snippet’s weight relative to the other snippets.
When you call the ChooseContent method, the component calls the MapPath
method of the Server object to determine the physical path for the virtual path you
pass as an argument to ChooseContent. The result of this method call is a small
HTML snippet that can be placed in the HTML sent to the client.
GetAllContent 307
Content Rotator
GetAllContent
ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved.
Parameters
strContentSchedFile
A string value representing the virtual or relative pathname and filename of
your content schedule file. You cannot use physical paths or absolute URLs
(those beginning with HTTP://, //, or \\) for this parameter.
Example
<HTML>
<HEAD>
<TITLE>Document List</TITLE>
<BODY>
<%
' Dimension local variables.
Dim objContentRotr
Dim strSelHTMLContent
' Create an instance of the Content Rotator object.
Set objContentRotr = _
Server.CreateObject("IISSample.ContentRotator")
' Retrieve a quotation from the Quote content schedule
' file for December.
strSelHTMLContent = objContentRotr.ChooseContent( _
"/SchedFiles/DecemberQuotes.txt")
' Now you can add the content thus retrieved to the
' HTML sent to the client.
%>
Today's quote:<BR>
<%= strSelHTMLContent %>
...[additional HTML and code]
Notes
Obviously, the more snippets of HTML code you add to the content schedule file,
the less likely any one will be selected more than once in a row, assuming all
have the same weight.
You will receive an error if you attempt to call the ChooseContent method from
within the GLOBAL.ASA file.
GetAllContent
objContentRotator.GetAllContent(strContentSchedFile)
Retrieves all the HTML snippets listed in the content schedule file. When you
display the content from the call to GetAllContent, each snippet will be separated
by a horizontal rule tag (<HR>) in the HTML.
308 Chapter 16 – Content Rotator Component
GetAllContent
ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved.
Parameters
strContentSchedFile
A string value representing the virtual or relative pathname and filename of
your content schedule file. You cannot use physical paths or absolute URLs
(those beginning with HTTP://, //, or \\) for this parameter.
Example
<HTML>
<HEAD>
<TITLE>Document List</TITLE>
<BODY>
<%
' Dimension local variables.
Dim objContentRotr
Dim strAllHTMLContent
' Create an instance of the Content Rotator object.
Set objContentRotr = _
Server.CreateObject("IISSample.ContentRotator")
' Retrieve all the quotes from the Quote content
' schedule file for December. The call to GetAllContent
' will separate each HTML snippet from the Content
' Schedule file with an <HR> tag.
strAllHTMLContent = objContentRotr.GetAllContent( _
"/SchedFiles/DecemberQuotes.txt")
' Now you can add the content thus retrieved to the
' HTML sent to the client.
%>
All quotes:<BR>
<%= strAllHTMLContent %>
...[additional HTML and code]
Notes
The primary use for this method is for maintenance of the content schedule file.
309
Counters
ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved.
ng list
\par file.
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par 292 Chapter 15 – Content Linking Component
\par GetNextDescription
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par GetNextDescription
\par objNextLink.GetNextDescription(strContentLinkList )
\par Returns a string containing the description of the next document listed \par in the
\par Content Linking list.
\par Parameters
\par strContentLinkList
\par A string value representing the virtual or relative pathname and filename \par of
\par your Content Linking file. You cannot use physical paths or absolute URLs
\par (those beginning with HTTP://, //, or \\\\) for this parameter.
\par Example
\par <HTML>
\par <HEAD>
\par <TITLE>Document List</TITLE>
\par <BODY>
\par <%
\par ' Dimension local variables.
\par Dim objNextLink
\par Dim strNextDesc
\par ' Create an instance of the NextLink object.
\par Set objNextLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve a description text for the next item in the
\par ' Content Linking list file.
\par strNextDesc = _
\par objNextLink.GetNextDescription("/MyContentLinkList.txt")
\par ' Display the next description to the client.
\par %>
\par <%= strNextDesc%>
\par <%
\par ' Free the memory consumed by the NextLink object.
\par Set objNextLink = Nothing
\par %>
\par ...[additional HTML and code]
\par Notes
\par If the current document is not listed in the Content Linking list file, \par the description
\par text for the last item in the list file is returned by default. If the \par current item is the
\par last item in the list, calling GetNextDescription returns an empty string \par (“”).
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par GetNextURL 293
\par Content Linking
\par GetNextURL
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par GetNextURL
\par objNextLink.GetNextURL(strContentLinkList)
\par Returns a string containing the URL entry of the next document listed \par in the
\par Content Linking list.
\par Parameters
\par strContentLinkList
\par A string value representing the virtual or relative pathname and filename \par of
\par your Content Linking file. You cannot use physical paths or absolute URLs
\par (those beginning with HTTP://, //, or \\\\) for this parameter.
\par Example
\par <%
\par ' Dimension local variables.
\par Dim objNextLink
\par Dim strNextDesc
\par Dim strNextURL
\par ' Create an instance of the NextLink object.
\par Set objNextLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve a description text for the next item in the
\par ' Content Linking list file.
\par strNextDesc = _
\par objNextLink.GetNextDescription("/MyContentLinkList.txt")
\par ' Retrieve a URL for the next item in the Content Linking
\par ' list file.
\par strNextURL = _
\par objNextLink.GetNextURL("/MyContentLinkList.txt")
\par ' Use strNextURL to create a link to the item whose
\par ' description you retrieved using GetNextDescription.
\par %>
\par <A HREF = "<%= strNextURL %>"><%= strNextDesc%></A>
\par <%
\par ' Free the memory consumed by the NextLink object.
\par Set objNextLink = Nothing
\par %>
\par ...[additional HTML and code]
\par Notes
\par If the current document is not listed in the Content Linking list file, \par the URL text
\par for the last item in the list file is returned by default.
\par Using GetNextURL with a Content Linking file, you do not have to change \par the
\par code within your HTML to update a “NEXT PAGE” hyperlink, for \par example. You
\par 294 Chapter 15 – Content Linking Component
\par GetNthDescription
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par have only to change the Content Linking list, and the component will automatically
\par update this link for you.
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par GetNthDescription
\par objNextLink.GetNthDescription(strContentLinkList, intItemIndex)
\par Returns a string containing the description for the item in the Nth position \par (on the
\par Nth line) in the Content Linking list.
\par Parameters
\par strContentLinkList
\par A string value representing the virtual or relative pathname and filename \par of
\par your Content Linking file. You cannot use physical paths or absolute URLs
\par (those beginning with HTTP://, //, or \\\\) for this parameter.
\par intItemIndex
\par An integer indicating the index of the item whose description you wish \par to
\par retrieve from the Content Linking list.
\par Example
\par <%
\par ' Dimension local variables.
\par Dim objNextLink
\par Dim intTotalCount
\par Dim intCounter
\par ' Instantiate a NextLink object for this script.
\par Set objNextLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve a total count of items in the Content Linking file.
\par intTotalCount = _
\par objNextLink.GetListCount("/MyContentList.TXT")
\par ' Iterate through all the items in the Content Linking
\par ' list and generate an entry in an ordered list.
\par %>
\par <OL>
\par <UL>
\par <%
\par For intCounter = 1 to intTotalCount
\par %>
\par <LI>
\par <!-- Create a hyperlink to the URL for the current item -->
\par <!-- in the list. -->
\par <a href "<%=
\par objNextLink.GetNthURL("/MyContentList.TXT", _
\par intCounter)%>">
\par <!-- Retrieve the text description for that URL. -->
\par GetNthURL 295
\par Content Linking
\par GetNthURL
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par objNextLink.GetNthDescription("/MyContentList.TXT", _
\par intCounter)
\par </LI>
\par <%
\par Next
\par %>
\par </UL>
\par </OL>
\par <%
\par ' Release the memory held for the NextLink object.
\par Set objNextLink = Nothing
\par %>
\par Notes
\par If there is not an item in the position sent in the intItemIndex parameter, \par an
\par error results. To prevent this, you can compare the value to be supplied \par as the
\par intItemIndex argument with the value returned by a call to the GetListCount
\par method.
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par GetNthURL
\par objNextLink.GetNthURL(strContentLinkList, intItemIndex)
\par Returns a string containing the URL for the item in the Nth position (on \par the Nth
\par line) in the Content Linking list.
\par Parameters
\par strContentLinkList
\par A string value representing the virtual or relative pathname and filename \par of
\par your Content Linking file. You cannot use physical paths or absolute URLs
\par (those beginning with HTTP://, //, or \\\\) for this parameter.
\par intItemIndex
\par The index of the item in the Content Linking list whose URL you wish to
\par retrieve. This is an integer parameter.
\par Example
\par <%
\par ' Dimension local variables.
\par Dim objNextLink
\par Dim intTotalCount
\par Dim intCounter
\par ' Instantiate a NextLink object for this script.
\par Set objNextLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve a total count of items in the Content
\par ' Linking file.
\par intTotalCount = _
\par 296 Chapter 15 – Content Linking Component
\par GetPreviousDescription
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par objNextLink.GetListCount("/MyContentList.TXT")
\par ' Iterate through all the items in the Content Linking
\par ' list and generate an entry in an ordered list.
\par %>
\par <OL>
\par <UL>
\par <%
\par For intCounter = 1 to intTotalCount
\par %>
\par <LI>
\par <!-- Create a hyperlink to the URL for the current -->
\par <!-- item in the list. -->
\par <a href "<%=
\par objNextLink.GetNthURL("/MyContentList.TXT", _
\par intCounter)%>">
\par <!-- Retrieve the text description for that URL. -->
\par objNextLink.GetNthDescription("/MyContentList.TXT", _
\par intCounter)
\par </LI>
\par <%
\par Next
\par %>
\par </UL>
\par </OL>
\par <%
\par ' Release the memory held for the NextLink object.
\par Set objNextLink = Nothing
\par %>
\par Notes
\par If there is not an item in the position indicated by the intItemIndex \par parameter,
\par an error results. To prevent this, you can compare the value to be supplied \par as the
\par intItemIndex argument with the value returned by a call to the GetListCount
\par method.
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par GetPreviousDescription
\par objNextLink.GetPreviousDescription(strContentLinkList )
\par Returns an ASCII string containing the description of the previous document \par listed
\par in the Content Linking list.
\par GetPreviousURL 297
\par Content Linking
\par GetPreviousURL
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par Parameters
\par strContentLinkList
\par A string value representing the virtual or relative pathname and filename \par of
\par your Content Linking file. You cannot use physical paths or absolute URLs
\par (those beginning with HTTP://, //, or \\\\) for this parameter.
\par Example
\par <HTML>
\par <HEAD>
\par <TITLE>Document List</TITLE>
\par <BODY>
\par <%
\par ' Dimension local variables.
\par Dim objNextLink
\par Dim strPrevDesc
\par ' Create an instance of the NextLink object.
\par Set objNextLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve a description text for the previous item in
\par ' the Content Linking list file.
\par strPrevDesc = _
\par objNextLink.GetPreviousDescription("/MyContentLinkList.txt")
\par ' Display the previous description to the client.
\par %>
\par <%= strPrevDesc%>
\par <%
\par ' Free the memory consumed by the NextLink object.
\par Set objNextLink = Nothing
\par %>
\par ...[additional HTML and code]
\par Notes
\par If the current page cannot be found in the Content Linking list file, \par the description
\par text for the first item in the list file is returned by default. If the \par current item is the
\par first item in the list, calling GetPreviousDescription will return an \par empty string (“”).
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par GetPreviousURL
\par objNextLink.GetPreviousURL(strContentLinkList)
\par Returns a string containing the URL entry of the previous document listed \par in the
\par Content Linking list.
\par 298 Chapter 15 – Content Linking Component
\par GetPreviousURL
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par Parameters
\par strContentLinkList
\par A string value representing the virtual or relative pathname and filename \par of
\par your Content Linking file. You cannot use physical paths or absolute URLs
\par (those beginning with HTTP://, //, or \\\\) for this parameter.
\par Example
\par <%
\par ' Dimension local variables.
\par Dim objNextLink
\par Dim strPrevDesc
\par Dim strPrevURL
\par ' Create an instance of the NextLink object.
\par Set objNextLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve a description text for the previous item in
\par ' the Content Linking list file.
\par strPrevDesc = _
\par objNextLink.GetPreviousDescription("/MyContentLinkList.txt")
\par ' Retrieve a URL for the previous item in the Content
\par ' Linking list file.
\par strPrevURL = _
\par objNextLink.GetPreviousURL("/MyContentLinkList.txt")
\par ' Use strNextURL to create a link to the item whose
\par ' description you retrieved using GetPreviousDescription.
\par %>
\par <A HREF = "<%= strPrevURL %>"><%= strPrevDesc%></A>
\par <%
\par ' Free the memory consumed by the NextLink object.
\par Set objNextLink = Nothing
\par %>
\par ...[additional HTML and code]
\par Notes
\par If the current page cannot be found in the Content Linking list file, \par the URL text
\par for the first item in the list file is returned by default.
\par Using GetPreviousURL with a Content Linking file, you do not have to change \par the
\par code within your HTML to update a “PREVIOUS PAGE” hyperlink, \par for example.
\par You only have to change the Content Linking list, and the component will \par automatically
\par update this link for you.
\par In addition to the previous example, see the full example at the end of \par this
\par chapter.
\par Content Linking Component Example 299
\par Content Linking
\par Content Linking Component Example
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par Content Linking Component Example
\par The following example code demonstrates a complete Content Linking component
\par example in one place to illustrate the overall mechanism of the Content
\par Linking component and its accessory content list file.
\par The scenario is simple. The following set of scripts demonstrates the \par dynamic
\par construction of the first few pages of an online book introducing programming.
\par There are five content files (Content1.ASP through Content5.ASP). For \par each file,
\par you want to provide your users with an indicator of current page number \par (out of
\par the total number of pages), a previous-page link, and a next-page link. \par You know
\par the content files will change and pages will be inserted and removed often. \par This is
\par a good example of a programming problem in which the Content Linking component
\par can help.
\par The following script is the HTML version of the fourth page in our online \par book:
\par <HTML>
\par <HEAD><TITLE>Introduction to Programming: Lesson 4 Looping</
\par TITLE></HEAD>
\par <BODY>
\par Welcome to the Introduction to Programming, Lesson 4:
\par Looping.<BR>
\par [TEXT ABOUT LOOPING AND LOOP STRUCTURES]
\par <!-- Begin navigation section construction -->
\par <HR>
\par You are currently viewing page # 4 of 5.<BR>
\par Use the following links to navigate:<BR>
\par <A HREF "Content3.asp">Previous: Lesson 3 Variables</A><BR>
\par <A HREF "Content1.asp">Home: Lesson 1 Introduction</A><BR>
\par <A HREF "Content5.asp">Next: Lesson 5 Pointers</A><BR>
\par <!-- End navigation section construction -->
\par </BODY>
\par </HTML>
\par This HTML page could be easily created by hand and kept up-to-date manually
\par when pages are inserted and removed. However, you can see that with many
\par pages, such upkeep would be tedious, at best. For example, suppose we \par had to
\par insert a page (Lesson 3a: Advanced Variables) between lessons 3 and 4. \par To do this
\par manually, everything in bold in the previous example would have to be \par changed
\par by hand. If we removed the current home page and added a new one (with \par a
\par different name and description), we would have to make even more changes.
\par The Content Linking component can help us here. We start by creating a \par Content
\par Linking list, whose filename is ONLINE_CONTENT_LIST.TXT:
\par Content1.asp Lesson 1 Background
\par Content2.asp Lesson 2 Code Style
\par Content3.asp Lesson 3 Variables
\par Content4.asp Lesson 4 Looping
\par Content5.asp Lesson 5 Pointers
\par 300 Chapter 15 – Content Linking Component
\par Content Linking Component Example
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par The file contains one line for each of our five content pages. Each line \par consists of
\par a filename and a file description, separated by a Tab character. We can \par now add
\par the following code to the navigation section of each page in our online \par book:
\par <!-- Begin navigation section construction -->
\par <HR>
\par <%
\par Dim objContentLink
\par Set objContentLink = Server.CreateObject("MSWC.NextLink")
\par ' Retrieve the index of the current page.
\par intCurrentPageNumber = _
\par objContentLink.GetListIndex("ONLINE_CONTENT_LIST.TXT")
\par ' Retrieve the total number of pages.
\par intTotalPageCount = _
\par objContentLink.GetListCount("ONLINE_CONTENT_LIST.TXT")
\par ' Retrieve the URL for the first page in the series.
\par strHomeURL = _
\par objContentLink.GetNthURL("ONLINE_CONTENT_LIST.TXT", 1)
\par ' Retrieve the description for the first page in the series
\par strHomeDesc = objContentLink.GetNthDescription( _
\par "ONLINE_CONTENT_LIST.TXT", 1)
\par ' If the current page index is greater than 1 (i.e., it
\par ' is after the home page), then retrieve information
\par ' about the previous page.
\par If intCurrentPageNumber > 1 Then
\par ' Retrieve the description for the first page in the
\par ' series.
\par strPrevURL = objContentLink.GetPreviousURL( _
\par "ONLINE_CONTENT_LIST.TXT", 1)
\par ' Retrieve the description for the previous page in
\par ' the series.
\par strPrevDesc = objContentLink.GetPreviousDescription( _
\par "ONLINE_CONTENT_LIST.TXT", 1)
\par End If
\par ' If the current page index is less than the total page
\par ' count (i.e., it is before the last page), then retrieve
\par ' information about the next page.
\par If intCurrentPageNumber < intTotalPageCount Then
\par ' Retrieve the URL for the previous page in the series.
\par strNextURL = objContentLink.GetNextURL( _
\par "ONLINE_CONTENT_LIST.TXT", 1)
\par ' Retrieve the description for the next page in the series.
\par strNextDesc = objContentLink.GetNextDescription( _
\par "ONLINE_CONTENT_LIST.TXT", 1)
\par Content Linking Component Example 301
\par Content Linking
\par Content Linking Component Example
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par End If
\par ' Now use the preceding information to construct the
\par ' navigation section of the current page.
\par %>
\par You are currently viewing page #
\par <%=intCurrentPageNumber%> of
\par <%=intTotalPageCount%>.<BR>
\par Use the following links to navigate:<BR>
\par <%If intCurrentPageNumber > 1 Then%>
\par <A HREF "<%=strPrevURL%>">Previous:
\par <%=strPrevDesc%></A><BR>
\par <%End If%>
\par <A HREF "<%=strHomeURL%>">Home: <%=strHomeDesc%></A><BR>
\par <%If intCurrentPageNumber < intTotalPageCount%>
\par <A HREF "<%=strNextURL%>">Next: <%=strNextDesc%></A><BR>
\par <%End If%>
\par <!-- End navigation section construction -->
\par If we were to replace the following code in bold:
\par <HTML>
\par <HEAD><TITLE>Introduction to Programming: Lesson 4 Looping</
\par TITLE></HEAD>
\par <BODY>
\par Welcome to the Introduction to Programming, Lesson 4:
\par Looping.<BR>
\par [TEXT ABOUT LOOPING AND LOOP STRUCTURES]
\par <!-- Begin navigation section construction -->
\par <HR>
\par You are currently viewing page # 4 of 5.<BR>
\par Use the following links to navigate:<BR>
\par <A HREF "Content3.asp">Previous: Lesson 3 Variables</A><BR>
\par <A HREF "Content1.asp">Home: Lesson 1 Introduction</A><BR>
\par <A HREF "Content5.asp">Next: Lesson 5 Pointers</A><BR>
\par <!-- End navigation section construction -->
\par </BODY>
\par </HTML>
\par with the Content Linking component code segment preceding it, the result \par would
\par be a navigation links section that stays current with the Content Linking \par list. All
\par you would have to do to update the links is to update the Content Linking \par list file.
\par We could even go one step further and save the previous code as an include \par file
\par (called NavConstruct.INC) and include it anywhere in the content pages \par for our
\par online book:
\par <HTML>
\par <HEAD><TITLE>Introduction to Programming: Lesson 4 Looping
\par </TITLE></HEAD>
\par 302 Chapter 15 – Content Linking Component
\par Content Linking Component Example
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par <BODY>
\par Welcome to the Introduction to Programming, Lesson 4:
\par Looping.<BR>
\par [TEXT ABOUT LOOPING AND LOOP STRUCTURES]
\par <!-- #INCLUDE FILE = NavConstruct.INC-->
\par </BODY>
\par Now suppose we must add a page between pages 3 and 4. All that we must \par do,
\par after creating the page itself (and including our NavConstruct.INC include \par file), is
\par to update the ONLINE_CONTENT_LIST.TXT Content Linking list file:
\par Content1.asp Lesson 1 Background
\par Content2.asp Lesson 2 Code Style
\par Content3.asp Lesson 3 Variables
\par Content3a.asp Lession 3a Advanced Variables
\par Content4.asp Lesson 4 Looping
\par Content5.asp Lesson 5 Pointers
\par All the links constructed using the Content inking list component are \par updated
\par upon the code’s execution and the links stay correct. You can avoid \par the task of
\par going into each affected file and updating hardcoded links. It is all \par done for you.
\par 303
\par Content Rotator
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par } the Cc list \par for the
\par current message.
\par 272 Chapter 14 – Collaboration Data Objects for Windows NT Server
\par ContentBase
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par <%
\par ' Dimension local variables.
\par Dim objNewMail
\par Dim strCCRecipList
\par ' Instantiate a NewMail object.
\par Set objNewMail = Server.CreateObject("CDONTS.NewMail")
\par ' Set the Bcc property of the NewMail object to the following
\par ' email addresses: (1) billw@firebird.com and
\par ' (2) helen@zoologyzine.com.
\par strCCRecipList = _
\par "billw@firebird.com;helen@zoologyzine.com"
\par objNewMail.Cc = strCCRecipList
\par ' Set the body string for the message.
\par objNewMail.Body = _
\par "Wow, this message takes just a few lines of code."
\par ' Send the message. For details about the Send method,
\par ' see that section in this chapter.
\par objNewMail.Send(,,"This is the subject",,cdoHigh)
\par %>
\par Notes
\par As demonstrated in the example, the string you use to set the Cc property \par can
\par contain a single email address or multiple email addresses separated by
\par semicolons.
\par ContentBase
\par objNewMail.ContentBase = strContentBase
\par A string representing the base for all URLs referenced within the body \par of the
\par message content. This property is used only for MIME HTML (for more information
\par on MHTML, see RFC 2110). The ContentBase property represents the URL on
\par which all relative URLs in the HTML section of the body are based.
\par Parameters
\par strContentBase
\par A string containing a base URL for all URLs in the content HTML for the
\par current message
\par Example
\par The following example demonstrates the use of the ContentBase property \par in
\par conjunction with the ContentLocation property (see its entry later in \par the following
\par section).
\par ContentBase 273
\par Collaboration Data Objects
\par ContentBase
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par <%
\par ' Dimension local variables.
\par Dim objNewMail
\par Dim strBodyContent
\par ' Instantiate a NewMail object.
\par Set objNewMail = Server.CreateObject("CDONTS.NewMail")
\par ' Set the body string for the message.
\par strBodyContent = "<HTML><HEAD><TITLE>"
\par strBodyContent = strBodyContent & "My HTML Content"
\par strBodyContent = strbodyContent & "</TITLE></HEAD><BODY>"
\par strBodyContent = strBodyContent & "Here is an excellent image:"
\par strBodyContent = strBodyContent & "<BR>"
\par strBodyContent = strBodyContent & "<IMG SRC = "TodaysPic.jpg">"
\par strBodyContent = strBodyContent & _
\par "<BR>I hope you like today's picture.</BODY>"
\par ' Set the ContentBase and ContentLocation so the messaging
\par ' system knows how to resolve the simple URL in the preceding
\par ' image tag.
\par objNewMail.ContentBase = "http://www.MyPrimarySvr.com/"
\par objNewMail.ContentLocation = "graphics/dailypics/"
\par ' Now the preceding img tag can be resolved to:
\par ' www.MyPrimarySvr.com/graphics/dailypics/TodaysPic.jpg
\par ' when it is displayed on the recipient's mail client.
\par ' Set the BodyFormat so that the NewMail object
\par ' treats the body contents as HTML.
\par objNewMail.BodyFormat = cdoBodyFormatHTML
\par ' Set the body content string for the NewMail object.
\par objNewMail.Body = strBodyContent
\par ' Send the message. For details about the Send method,
\par ' see that section in this chapter.
\par objNewMail.Send("me@here.com","you@there.com", _
\par "This is the subject",,cdoHigh)
\par %>
\par Notes
\par The ContentBase and ContentLocation properties are useful only for message \par body
\par content containing HTML.
\par The ContentBase property is to the URLs in the body HMTL content what \par the
\par ContentBase argument of the AttachURL method is to URLs in attached HTML \par files.
\par 274 Chapter 14 – Collaboration Data Objects for Windows NT Server
\par ContentLocation
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par ContentLocation
\par objNewMail.ContentLocation = strContentLocation
\par A string property representing the absolute or relative path for all URLs \par referenced
\par within the body of the message content.
\par Parameters
\par strContentLocation
\par A string containing a relative or absolute path for all URLs in the content
\par HTML for the current message
\par Example
\par See the example for the ContentBase property in the preceding section.
\par Notes
\par The ContentBase and ContentLocation properties are useful only for message \par body
\par content containing HTML.
\par The ContentLocation property of the NewMail object is to the URLs in the \par body
\par HMTL content what the ContentLocation argument of the AttachURL method \par is to
\par URLs in attached HTML files.
\par From
\par objNewMail.From = strSenderAddr
\par A string value that represents the full messaging address of the sender \par of the
\par current message.
\par Parameters
\par strSenderAddr
\par A string value containing the messaging address of the person or process \par that
\par is sending the current NewMail object. This address is not resolved (checked)
\par before it is placed in the mail header sent with the NewMail object.
\par Example
\par This example demonstrates the use of the From property. It also shows \par that if you
\par set the From property and also include a From string in the Send method \par call, the
\par setting you used for the From property is ignored and only the string \par sent to the
\par Send method is actually used.
\par <%
\par ' Dimension local variables.
\par Dim objNewMail
\par ' Instantiate a NewMail object.
\par Set objNewMail = Server.CreateObject("CDONTS.NewMail")
\par ' Set the body string for the message.
\par Importance 275
\par Collaboration Data Objects
\par Importance
\par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition
\par Copyright © 2000 O’Reilly & Associates, Inc. All rights \par reserved.
\par objNewMail.Body = _
\par "Wow, this message takes just a few lines of code."
\par ' Set the From property to the sender's email address.
\par objNewMail.From = "sender@usacom.com"
\par ' Send the message. For details about the Send method,
\par ' see that section in this chapter.
\par ' NOTE: Because we are including a value for the From
\par ' parameter to the Send method call, the value here
\par ' is actually sent to the message's recipient.
\par objNewMail.Send("me@here.com","you@there.com", _
\par "This is the subject",,cdoHigh)
\par %>
\par Notes
\par If you set the value of the From property and then also include a From \par parameter
\par i