Scott Mitchell, Bill Anders, Rob Howard, Doug Seven, Stephen Walther, Christop Wille, and Don Wolthuis
201 West 103rd St., Indianapolis, Indiana, 46290 USA
0-672-32143-2 Spring 2001
Common ASP.NET Code Techniques
CHAPTER
2
29
IN THIS CHAPTER
• Using Collections 4 • Working with the File System • Using Regular Expressions 45 51 60 64
• Generating Images Dynamically
• Sending E-mail from an ASP.NET Page • Network Access Via an ASP.NET Page
• Uploading Files from the Browser to the Web Server Via an ASP.NET Page 71 • Using ProcessInfo: Retrieving Information About a Process 79 • Accessing the Windows Event Log • Working with Server Performance Counters 93 • Encrypting and Decrypting Information 101 84
4
Common ASP.NET Code Techniques CHAPTER 2
Using Collections
Most modern programming languages provide support for some type of object that can hold a variable number of elements. These objects are referred to as collections, and they can have elements added and removed with ease without having to worry about proper memory allocation. If you’ve programmed with classic ASP before, you’re probably familiar with the Scripting.Dictionary object, a collection object that references each element with a textual key. A collection that stores objects in this fashion is known as a hash table. There are many types of collections in addition to the hash table. Each type of collection is similar in purpose: it serves as a means to store a varying number of elements, providing an easy way, at a minimum, to add and remove elements. Each different type of collection is unique in its method of storing, retrieving, and referencing its various elements. The .NET Framework provides a number of collection types for the developer to use. In fact, an entire namespace, System.Collections, is dedicated to collection types and helper classes. Each of these collection types can store elements of type Object. Because in