ASP - The Content Linking Component

To use the Content Linking component, you must do the following

Prepare the Content Linking List File

The Content Linking List File is the material that the the Content Linking Component will read data into. The topics must be entered in a text file, each one on its own line. Each line in this file has the following structure.

DocumentURL          Description           Comments

Successive items on a line are separated by a tab character, which makes the file a bit difficult to read. The DocumentURL item is the URL of a page, and Description is a descriptive title for the same page. When you write the code to insert the usual navigational hyperlinks, DocumentURL will become the destination address of a hyperlink and Description will become the hyperlink's title. The last item, Comments, is optional; it's included as an aid to the developer and is ignored by the Content Linking component.

Every time the user selects the First/Next/Previous/Last hyperlink, the appropriate document will be displayed. Exactly which document will appear depends on the list file's contents and the document being displayed at the moment.

Example of the Content Linking List File

ad_rotator_component.php           Ad Rotator Component
cdonts.php                                 Send mail with CDONT.NewMail
cookies.php                                How to use Cookie in ASP
server_object.php                        The Server Object

Name this file ASPObjectsTOC.txt and save it in the virtual folder of the application.

Note that the file you written must be existed on the server so that the link is valid.

Write Code to add Navigational Buttons to Your Pages

The navigational buttons are added at the top or bottom of the page and are the usual First/Previous/Next/Last hyperlinks. The destinations of these hyperlinks are read from the Content Linking list file and inserted on each page with a short script. The same script must be inserted on each page, so you should place all statements in an Include file. Insert an #INCLUDE FILE directive, like the following one, in each page at the place where the hyperlinks should appear:

<!-- #INCLUDE FILE = NavigationCode.inc-->

Then, the NavigationCode.inc file should be written as follow:

<%
Set objContents = Server.CreateObject("MSWC.NextLink")
PageCount = objContents.GetListCount("ASPObjectsTOC.txt")
curPage = objContents.GetListIndex("ASPObjectsTOC.txt")

Response.Write "<table width=100%>"
If curPage > 2 Then
    firstUrl = objContens.GetNthURL("ASPObjectsTOC.txt", 1)
    firstDescription = objContents.GetNthDescription("ASPObjectsTOC.txt", 1)
    Response.Write "<td align=center>"
    Response.Write "<a href='" & firstUrl & "'><b>First</b></a><br>"
    Response.Write "<a href='" & firstUrl & "'>" & firstDescription & "</a>"
    Response.Write "</td>"
End If

If curPage > 1 Then
    prevUrl = objContens.GetPreviousURL("ASPObjectsTOC.txt")
    prevDescription = objContents.GetPreviousDescription("ASPObjectsTOC.txt")
    Response.Write "<td align=center>"
    Response.Write "<a href='" & prevUrl & "'><b>Previous</b></a><br>"
    Response.Write "<a href='" & prevUrl & "'>" & prevDescription & "</a>"
    Response.Write "</td>"
End If

If curPage < PageCount Then
    nextUrl = objContens.GetNextURL("ASPObjectsTOC.txt")
    nextDescription = objContents.GetNextDescription("ASPObjectsTOC.txt")
    Response.Write "<td align=center>"
    Response.Write "<a href='" & nextUrl & "'><b>Next</b></a><br>"
    Response.Write "<a href='" & nextUrl & "'>" & nextDescription & "</a>"
    Response.Write "</td>"
End If

If curPage < PageCount Then
    lastUrl = objContens.GetNthURL("ASPObjectsTOC.txt", PageCount)
    lastDescription = objContents.GetNthDescription("ASPObjectsTOC.txt", PageCount)
    Response.Write "<td align=center>"
    Response.Write "<a href='" & lastUrl & "'><b>Last</b></a><br>"
    Response.Write "<a href='" & lastUrl & "'>" & lastDescription & "</a>"
    Response.Write "</td>"
End If
Response.Write "</table>"

Set objContent = Nothing

Name this file NavigationCode.inc and store it in the site's virtual folder. You can now test the site by connecting to the first page. The NavigationCode.inc file must be included in every page of the site.

Methods

GetListCount

This method returns the number of topics (URLs and descriptions) in a Content Linking list file. The syntax of GetListCount is:

objContents.GetListCount(contentFileName)

contentFileName is the path and name of the Content Linking list file. The path is relative to the current virtual folder, and it can't be a physical or absolute URL.

GetListIndex

The GetListIndex method returns an integer, which is the order of the current page in the content list. Use this method to find out from within your code which page is displayed on the client, in the following syntax:

objContents.GetListIndex(contentFileName)

contentFileName is the path and name of the Content Linking list file. The path is relative to the current virtual folder, and it can't be a physical or absolute URL.

GetNextDescription

This method returns the description of the next item in the Content Linking list file. If the current item is the last one in the file, then the GetNextDescription method returns the description of the first item in the list file.

objContents.GetNextDescription(contentFileName)

contentFileName is the path and name of the Content Linking list file. The path is relative to the current virtual folder, and it can't be a physical or absolute URL.

GetNextURL

This method returns the URL of the next item in the Content Linking list file. Use the value returned by this method as the Next hyperlink on the page. If the current item is the last one in the file, then the GetNextURL method returns the URL of the first item in the list file when called as follows:

objContents.GetNextURL(contentFileName)

contentFileName is the path and name of the Content Linking list file. The path is relative to the current virtual folder, and it can't be a physical or absolute URL. If an item doesn't have a URL (this shouldn't really happen in a well-designed site) , then an empty string will be returned.

GetNthDescription

This method returns the description of an arbitrary item in the Content Linking list file. Use the value returned by this method as the description of an item (hyperlink) in a navigational frame.

objContents.GetNthDescription(contentFileName, itemIndex)

contentFileName is the path and name of the Content Linking list file, and itemIndex is the index of the item whose description you want to retrieve. Notice that the index of the first item is 1, not 0. If an item doesn't have a URL (this shouldn't really happen in a well-designed site) , then an empty string will be returned.

If the itemIndex argument's value exceeds the number of items in the Content Linking list file, a runtime error will be generated. To avoid this error, you must make sure that the argument itemIndex doesn't exceed the value returned by the GetListCount method.

GetNthURL

This method returns the URL of an arbitrary item in the Content Linking list file. Use the value returned by this method as the destination of an item (hyperlink) in a navigational frame.

objContents.GetNthURL(contentFileName, itemIndex)

contentFileName is the path and name of the Content Linking list file, and itemIndex is the index of the item whose description you want to retrieve. Notice that the index of the first item is 1, not 0. If an item doesn't have a URL (this shouldn't really happen in a well-designed site) , then an empty string will be returned.

If the itemIndex argument's value exceeds the number of items in the Content Linking list file, a runtime error will be generated. To avoid this error, you must make sure that the argument itemIndex doesn't exceed the value returned by the GetListCount method.

GetPreviousDescription

This method returns the description of the previous item in the Content Linking list file. Use the value returned by this method as the description of the Previous hyperlink on your page.

objContents.GetPreviousDescription(contentFileName) 

contentFileName is the path and name of the Content Linking list file. If the current page isn't in the Content Linking list file, then the description of the first item in the file is returned. If the current page is the first one in the file, then the GetPreviousDescription returns the description of the first item in the file.

GetPreviousURL

This method returns the URL of the previous item in the Content Linking list file. Use the value returned by this method as the destination of the Previous hyperlink on your page.

objContents.GetPreviousURL(contentFileName)

contentFileName is the path and name of the Content Linking list file. If the current page isn't in the Content Linking list file, then the URL of the first item in the file is returned. If the current page is the first one in the file, then the GetPreviousURL returns the URL of the first item in the list file.