ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Displaying the newsletter archives --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
163 active users
3154 visitors today
4717 pages today
how is this done?
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

Caching the archive names

Rather than walking through the Newsletters folder and getting a list of filenames every time someone visits the archive, I store the filenames (which are really the dates of the newsletters) in Application variables. (Read more about Application variables)

// get data from Application variable
nTotal = Application ( 'TotalNewsletters' ) - 0;

if ( isNaN ( nTotal ) )
{
   // no newsletters in Application, so add them
   nTotal = 0;

   /* WalkFolders( ) goes here */

   // add to Application
   Application.Lock ( );

   Application ( 'TotalNewsletters' ) = nTotal;

   for ( var nIssue=0; nIssue<nTotal; nIssue++ )
      Application ( 'Newsletter' + nIssue ) = sDates [ nIssue ];

   Application.Unlock ( );
}
else
{
   // get data from Application (saved earlier)
   for ( var nIssue=0; nIssue<nTotal; nIssue++ )
      sDates [ nIssue ] = '' + Application ( 'Newsletter' + nIssue );
}

The first variable we use is "TotalNewsletters", which of course is one result of the previous WalkFolders( ) call. We can tell if the variable has been set yet by testing it with the built-in function IsNaN (NaN means Not-A-Number). If it's NaN then it's initialized to 0 and WalkFolders( ) called to set it and the sDates array.

Next the Application is locked so we can add some new variables. As an example, I create "Newsletter0" - "Newsletter20" if there are 20 newsletters found, and the variables contains the date of the newsletter. The the Application is unlocked.

Next time through, "TotalNewsletters" will contain a real number, so the sDates array is filled in from the "Newsletter0" - "Newsletter20" variables, saving all those FileSystemObject calls.

Part 4: Displaying the available dates...

Featured sponsor
My favorite resources

Selling products online - read how James does it now


CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!