Home arrow ASP arrow Page 2 - Managing Multi-page Articles with Content linking Component
ASP

Managing Multi-page Articles with Content linking Component


In this article Csaba eases the burden of linking ASP pages together by the use of Microsoft Content Linking installable. This is a must read.

Author Info:
By: Csaba Hatvany
Rating: 5 stars5 stars5 stars5 stars5 stars / 12
March 17, 2003
TABLE OF CONTENTS:
  1. · Managing Multi-page Articles with Content linking Component
  2. · The Content Linking
  3. · Conclusion

print this article
SEARCH DEVARTICLES

Managing Multi-page Articles with Content linking Component - The Content Linking
(Page 2 of 3 )

The Content Linking List File

The Content Linking component reads the needed information from a Content Linking List file that contains the list of the pages to be linked. Clearly, this list is stored on the web server. The Content Linking List file contains one line of text for each page in the list. Each line contains the items describing the corresponding page. There a maximal three items on a line corresponding to the URL of the page, a text description of the page and a comment. The items are separated with the TAB character. The first item is mandatory. Each line must end with a carriage return. Here is the format of a line in the Content Linking List file:

URL[<TAB>text description[<TAB>comment]]<CR>

The URL is the relative physical or virtual URL of the page beginning from the ASP page where the Content Linking component is instantiate. Absolute physical or virtual paths are not supported.

The Content Linking Component

We instantiate the Content Linking component as usual:

Dim objNextLink
Set objNextLink = Server.CreateObject("MSWC.NextLink")

(where MSWC stands for Microsoft Web Components).

The component has eight methods and one property:

  • GetListCount - returns the number of items linked in the Content Linking List file.
  • GetListIndex - returns the index of the current page in the Content Linking List file.
  • GetPreviousDescription - returns the description line of the previous page listed in the Content Linking List file.
  • GetPreviousURL - returns the URL of the previous pages listed in the Content Linking List file.
  • GetNextDescription - returns the description of the next page listed in the Content Linking List file.
  • GetNextURL  - returns the URL of the next page listed in the Content Linking List file.

All these methods have as unique parameter the URL of the Content Linking List file. The last to methods

  • GetNthDescription - returns the description of the Nth page listed in the Content Linking List file.
  • GetNthURL  - returns the URL of the Nth page listed in the Content Linking List file.

have as first parameter the URL of the Content Linking List file and as second parameter the index in the Content Linking List file of the page whose description or URL is to be returned.

The first page in the Content Linking List file has the index 1. If the current page is not in the Content Linking List file GetListIndex returns 0, GetPreviousDescription and GetPreviousURL return the description respectively the URL of the first page, and GetNextDescription and GetNextURL return the description respectively the URL of the last page. If the current page is the first page, GetPreviousDescription and GetPreviousURL return the description respectively the URL of the last page. Finally, if the current page is the last page, GetNextDescription and GetNextURL return the description respectively the URL of the first page.

The only property of the Content Linking component is the read-only property About which returns information about the version of the component in use.

How to Use?

Now, after this short overview of the Content Linking component letís see how to put all these together  to work.

We will organize our files as follows. In the directory article on the web server we will put the toc.txt Content Linking List file, the article.asp file and the pages subdirectory.

The toc.txt Content Linking List file contains the URLs and the descriptions of the pages of our article:

pages/page1.asp First Page this is the 1. page 
pages/page2.asp Second Page this is the 2. page
...
pages/page10.asp Tenth Page this is the 10. page

As you can already see we will put the pages in the pages directory, but for now let we see the file article.asp. This file generates the tables of contents:

<%@ LANGUAGE="VBScript" %>
<%Option Explicit
 Dim objNextLink
 Dim intListCount
 Dim intCount
 Dim strTOC
 strTOC = "toc.txt"
 ' create an instance of the Content Linking component
 Set objNextLink = Server.CreateObject("MSWC.NextLink")
 ' get the list count
intListCount = objNextLink.GetListCount(strTOC)
%>
<HTML>
<BODY>
<H1>Sample Article</H1>
<TABLE CELLSPACING=10>
 <TH><TR>
  <TD><B>Page</B></TD>
  <TD><B>Title</B></TD>
 </TR></TH>
 <TBODY>
<%
' display the links and the description for every page
 For intCount = 1 To intListCount
%>
 <TR>
  <TD align=right><%= intCount %></TD>
   <TD>
   <A HREF="<%= objNextLink.GetNthURL(strTOC, intCount)%>">
   <%= objNextLink.GetNthDescription(strTOC, intCount)%>
   </A>
  </TD>
 </TR>
<%
 Next
%>
</TBODY>
</TABLE>
</BODY>
</HTML>
<%
' free the memory
Set objNextLink = Nothing
%>

Here is what the user sees when downloading this file:

The pages directory contains the pages of the article and the navigation.asp file. This file creates the navigation menu using a new instance of the Content Linking component end a new Content Linking List file nav.txt situated in the same directory pages. The nav.txt file is a reduced Content Linking List file, while at this time we need only the URLs:

page1.asp
page2.asp
Ö
page10.asp

Note that the URLs in the nav.txt file must be relative to the pages directory where the navigation.asp file and the pages reside.

The article's pages are all similarly build. After the proper content these files include the navigation.asp file for the navigation menu:

<HTML>
<BODY>
<H1>First Page</H1>
<BR>
 Page content comes here
<BR>
<BR>
<!-- #include file="navigation.asp" -->
</BODY>
</HTML>

The navigation.asp file creates a new instance of the Content Linking component, gets the current page index and accordingly creates the links for the previous page, for the other pages, for the next page and a link back to the table of contents:

<%@ LANGUAGE="VBScript" %>
<%Option Explicit
 Dim objNextLink
 Dim intListIndex
 Dim intListCount
 Dim strNavigationFile
 Dim iCount
 ' create an instance of the Content Linking component
 Set objNextLink = Server.CreateObject("MSWC.NextLink")
 strNavigationFile = "nav.txt"
 ' get the list count
 intListCount = objNextLink.GetListCount(strNavigationFile)
 ' get the current pageís index
 intListIndex = objNextLink.GetListIndex(strNavigationFile)
 Response.Write "<div align=right>"
' link to the previous page
 If intListIndex >1 Then
  Response.Write "<a href=""page" & intListIndex-1 & _
".asp"">Previous Page</a>  "
 End If
 For iCount=1 To intListCount    
  ' do not link to the current page
  If iCount = intListIndex Then
   Response.Write iCount & " "
  ' link to all other page
  Else
   Response.Write "<a href=""page" & iCount & _
".asp"">" & iCount & "</a>  "
  End If    
 Next
 ' link to the next page
 If intListIndex < intListCount Then
  Response.Write "<a href=""page" & intListIndex+1 & _
".asp"">Next page</a>  "
 End If
' link to the TOC page
 Response.Write "<br>Back to the <a href=""../article.asp"">TOC</a>"
 Response.Write "</div>"
%>

Here is one page of the sample article:


blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials