Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
36 active users
1879 visitors today
2436 pages today
(only part of today)
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

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

Tiki Statues - Tiki Masks - Tiki Totems



See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!