![]() | * 3 Months FREE * CLICK HERE! | |
| CoverYourASP --> Displaying the newsletter archives --> Part 2 | ||
| Getting the list of newslettersLuckily I already had the perfect way to get a list of files in a folder or sub-folders, as described in my earlier article about the WalkFolders( ) function.The function works by walking through the files and folders on the server, passing what it finds into the functions that are passed into WalkFolders as parameters. Easily extensible as they say.
I first declare two global variables to store the list of newsletters found, and the total number of them. Then I create an instance of the FileSystemObject, and get a Folder object relating to the Newsletters sub-folder. Note: Server.MapPath is used to translate a relative path to an absolute path on the server Then WalkFolders is called, passing in the Folder object and the two functions that I will use to collect the file and folders that are found. Those functions are shown below:
I don't care about any folders that might be found, so I just supply an empty function for sending folder information. DisplayArchiveName gets passed a File object. First, as always, I ignore any files that start with '_' just in case I want to ever have any private files in the folder. I also ignore any files that don't have a 'txt' extension. Next, I remove the file extension with slice, and add the filename to the sDates array, incrementing nTotal at the same time. Note: As commented in the code above, you could dispense with nTotal altogether, and simply use sDates.push to add a new element to the array. Unfortunately, that's only available in JScript 5.5, which my server doesn't have yet. My development machine does, but the real one doesn't. Go figure! Now to throw the first "spanner in the works" as we English people say. For obvious reasons, I don't want to do this every time someone goes to view my archives. The answer is of course Application variables... |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||