Synopses & Reviews
Next time you hit the wall with a tough Visual Basic .NET problem, get the code behind the solution—and solve it the right way. This PROGRAMMER’S COOKBOOK provides at-a-glance reference to hundreds of Visual Basic .NET programming scenarios using a concise, problem/solution format. The book’s organized so you can quickly zero in on the topics and answers you need—with practical examples, code snippets, best practices, and undocumented secrets that get the job done.
No half-baked solutions. Get expert code from expert developers.
Get hundreds of recipes covering every application type—from Microsoft Windows to Web pages, Web services, remote components, and Windows services. Learn when to use lower-level Win32 APIs and COM components vs. the Microsoft .NET Framework Discover practical ways to deal with XML data and handle data binding with Microsoft ADO.NET. Build object-oriented components from scratch to access FTP sites, contact POP mail servers, and work with vectors, fractions, and complex numbers. Extend the reach of your Windows applications with WMI and use JavaScript to enhance Web pages. Tackle advanced techniques for multithreading, .NET Remoting, reflection, and cryptography. Uncover free third-party components to read zip files, write PDF documents, show menus in Microsoft ASP.NET, and more. Get all the book’s code recipes on line.Synopsis
Next time you hit the wall with a tough Visual Basic .NET problem, get the code behind the solution--and solve it the right way. This PROGRAMMER'S COOKBOOK provides at-a-glance reference to hundreds of Visual Basic .NET programming scenarios using a concise, problem/solution format. The book's organized so you can quickly zero in on the topics and answers you need--with practical examples, code snippets, best practices, and undocumented secrets that get the job done.
No half-baked solutions. Get expert code from expert developers. Get hundreds of recipes covering every application type--from Microsoft Windows to Web pages, Web services, remote components, and Windows services. Learn when to use lower-level Win32 APIs and COM components vs. the Microsoft .NET Framework Discover practical ways to deal with XML data and handle data binding with Microsoft ADO.NET. Build object-oriented components from scratch to access FTP sites, contact POP mail servers, and work with vectors, fractions, and complex numbers. Extend the reach of your Windows applications with WMI and use JavaScript to enhance Web pages. Tackle advanced techniques for multithreading, .NET Remoting, reflection, and cryptography. Uncover free third-party components to read zip files, write PDF documents, show menus in Microsoft ASP.NET, and more. Get all the book's code recipes on line.
About the Author
Matthew MacDonald is an author, educator, and MCSD developer with a passion for emerging technologies. He is the author of several books about programming with Microsoft .NET, a columnist for Inside Visual Basic, and a regular contributor to other periodicals such as ASPToday, C# Today, Hardcore ASP.NET, Hardcore VB .NET, and .NET Developer. In the corporate world, Matthew has worked with Microsoft technologies in a variety of roles, including as a technical writer, developer, and project manager. He also teaches introductory programming at the college level.
Table of Contents
Acknowledgments; Introduction; Feedback; Code Samples; System Requirements; Variable Naming; Other Books; Microsoft Press Support; Chapter 1: Strings and Regular Expressions; 1.1 Combine Strings; 1.2 Retrieve a Portion of a String; 1.3 Create a String Consisting of a Repeated Character; 1.4 Change the Case of All Characters in a String; 1.5 Perform Case-Insensitive String Comparisons; 1.6 Iterate Over All the Characters in a String; 1.7 Parse a String Into Words; 1.8 Find All Occurrences of Specific Text in a String; 1.9 Replace All Occurrences of Specific Text in a String; 1.10 Pad a String for Fixed-Width Display; 1.11 Reverse a String; 1.12 Insert a New Line in a String; 1.13 Insert a Special Character in a String; 1.14 Manipulate Strings Quickly with StringBuilder; 1.15 Convert a String into a Byte Array; 1.16 Get a String Representation of a Byte Array; 1.17 Use Common Regular Expressions; 1.18 Validate Input with a Regular Expression; 1.19 Find All Occurrences of a Pattern in a String; 1.20 Replace All Occurrences of a Pattern in a String; 1.21 Manipulate a Filename; 1.22 Manipulate a URI; 1.23 Validate a Credit Card with Luhns Algorithm; 1.24 Validate an ISBN; 1.25 Perform a SoundEx String Comparison; Chapter 2: Numbers, Dates, and Other Data Types; 2.1 Perform Mathematical and Trigonometric Operations; 2.2 Convert a Number into a Formatted String; 2.3 Generate a Random Number; 2.4 Work with NonBase 10 Number Systems; 2.5 Work with Complex Numbers; 2.6 Work with Vectors; 2.7 Work with Matrixes; 2.8 Work with Fractions Without Using Decimals; 2.9 Evaluate a String Expression; 2.10 Get the System Date and Time; 2.11 Add and Subtract Dates and Times; 2.12 Determine Days of the Week, Leap Years, and More; 2.13 Get Day and Month Names in Other Languages; 2.14 Format a Date; 2.15 Generate a Culture-Invariant Date String; 2.16 Validate a User-Supplied Date; 2.17 Generate a GUID; 2.18 Convert Basic Types to Binary; 2.19 Test Byte Arrays for Equality; 2.20 Convert the Name of an Enumerated Value into the Value; Chapter 3: Arrays and Collections; 3.1 Create and Populate an Array in One Step; 3.2 Resize an Array; 3.3 Create an Array That Is Not Bounded at Zero; 3.4 Create a Jagged Array; 3.5 Use a Dynamic ArrayList; 3.6 Fill an ArrayList from an Array; 3.7 Convert an ArrayList to an Array; 3.8 Sort Items in an Array or ArrayList; 3.9 Sort Non-Comparable Items in an Array or ArrayList; 3.10 Use a Hashtable Instead of a Generic Collection; 3.11 Enumerate Items in a Hashtable; 3.12 Use a Queue (FIFO Collection); 3.13 Use a Stack (LIFO Collection); 3.14 Use a Sorted List; 3.15 Create Shallow and Deep Copies of a Collection or Array; 3.16 Create a Strongly Typed Collection; 3.17 Create a Strongly Typed Dictionary Collection; 3.18 Remove Items While Iterating Through a Collection; 3.19 Iterate Through Collection Items in Random Order; Chapter 4: Objects, Interfaces, and Patterns; 4.1 Create a Value Type; 4.2 Create a Cloneable Object; 4.3 Create a Type-Safe Clone Method; 4.4 Create a Comparable Object; 4.5 Create a Disposable Object; 4.6 Create an Object That Can Appear in the Component Tray; 4.7 Create a Convertible Object; 4.8 Create a Serializable Object; 4.9 Serialize an Object to Disk; 4.10 Clone a Serializable Object; 4.11 Serialize Public Members of a Nonserializable Object; 4.12 Perform Selective Serialization with the Memento Pattern; 4.13 Throw a Custom Exception; 4.14 Raise a Custom Event; 4.15 Use the Singleton Pattern; 4.16 Use the Factory Pattern; 4.17 Use the Registry Pattern; 4.18 Use the Lazy Initialization Pattern; Chapter 5: Files and Directories; 5.1 Manipulate a File; 5.2 Manipulate a Directory; 5.3 Retrieve File Version Information; 5.4 Use Bitwise Arithmetic with File Attributes; 5.5 Read to and Write from a Binary File; 5.6 Filter Files with Wildcards; 5.7 Process Files Recursively; 5.8 Search for a File with Specific Text; 5.9 Fill a TreeView with a Just-In-Time Directory Tree; 5.10 Test Two Files for Equality; 5.11 Monitor the File System for Changes; 5.12 Create a Temporary File; 5.13 Get the Executable Path; 5.14 Set the Current Working Path; 5.15 Use an Isolated Store; 5.16 Read Application Configuration Settings; 5.17 Create Custom Configuration Sections; 5.18 Read Header Information from MP3 Files; 5.19 Get Started with ZIP Files; 5.20 Get Started with PDF Files; Chapter 6: XML; 6.1 Load an XML Document into Memory; 6.2 Process All Nodes in a Document; 6.3 Insert Nodes in an XML Document; 6.4 Find Specific Elements by Name; 6.5 Find Elements with an XPath Search; 6.6 Load an XML Document into a Class; 6.7 Use XML Serialization with Custom Objects; 6.8 Perform an XSL Transform; 6.9 Validate an XML Document Against a Schema; 6.10 Store Binary Data wwwwwwith a Base64 Transform; Chapter 7: Multithreading; 7.1 Call Any Method Asynchronously with a Delegate; 7.2 Wait for Several Asynchronous Calls to Complete; 7.3 Wait for One of Many Asynchronous Calls to Complete; 7.4 Use a Callback with an Asynchronous Call; 7.5 Perform an Asynchronous Task with the Thread Class; 7.6 Use Synchronization Code with Multiple Threads; 7.7 Use the Thread Object with a Task That Requires Data; 7.8 Use the Thread Object with a Task That Returns Data; 7.9 Marshal User Interface Code to the Correct Thread; 7.10 Stop a Thread Politely; 7.11 Create a Thread Wrapper Class; 7.12 Create a Reusable Task Processor; 7.13 Use a Pool of Threads; Chapter 8: Network Programming; 8.1 Get Web Connectivity Information for the Current Computer; 8.2 Get the IP Address of the Current Computer; 8.3 Look Up a Host Name for an IP Address; 8.4 Ping an IP Address; 8.5 Download a File Using HTTP; 8.6 Retrieve a Single Piece of Information from a Web Page; 8.7 Find All Links in a Web Page; 8.8 Communicate Using TCP; 8.9 Create a Multithreaded TCP Network Server; 8.10 Communicate Using UDP; 8.11 Send a Broadcast Message; 8.12 Send E-Mail Through SMTP; 8.13 Retrieve E-Mail Through POP3; 8.14 Access an FTP Site; Chapter 9: Reflection; 9.1 Generate a Dynamic About Box; 9.2 List Assembly Dependencies; 9.3 Get Type Information from a Class or an Object; 9.4 Examine a Type for Members; 9.5 Examine an Assembly for Types; 9.6 Instantiate a Type by Name; 9.7 Load an Assembly from a Remote Location; 9.8 Invoke a Method by Name; 9.9 Create, Apply, and Identify a Custom Attribute; 9.10 Identify the Caller of a Procedure; 9.11 Reflect on a WMI Class; 9.12 Compile Source Code Programmatically; Chapter 10: Windows Programming; 10.1 Access the Registry; 10.2 Retrieve Environment Variables; 10.3 Handle Operating System Events; 10.4 Access the Desktop and the Start Menu; 10.5 Create Desktop or Start Menu Shortcuts; 10.6 Start a Windows Application with a Main Subroutine; 10.7 Retrieve Command-Line Parameters; 10.8 Run the Application That Owns a File Extension; 10.9 Find Other Running Processes; 10.10 Terminate Another Process; 10.11 Allow Only One Instance of Your Application to Run; 10.12 Send Keystrokes to an Application; 10.13 Force a Windows Shutdown or Logoff; 10.14 Play a WAV File; 10.15 Display the Standard Directory Selection Dialog Box; 10.16 Use the Clipboard; 10.17 Display Context-Sensitive Help; 10.18 Catch Unhandled Errors; 10.19 Create a Windows Installer Setup Project; 10.20 Install the .NET Framework on a Client; 10.21 Associate a File Extension with Your Application; Chapter 11: Windows Controls; 11.1 Add a Control at Runtime; 11.2 Store Arbitrary Data in a Control; 11.3 Replace a Control Array; 11.4 Clear All Controls on a Form; 11.5 Store Objects in a List; 11.6 Force a ListBox to Scroll; 11.7 Use a Hyperlink; 11.8 Restrict a Text Box to Numeric Input; 11.9 Use an Auto-Complete Combo Box; 11.10 Sort a ListView Based on Any Column; 11.11 Use the Drag-and-Drop Feature; 11.12 Show a Linked Context Menu Generically; 11.13 Use Part of the Main Menu for a Context Menu; 11.14 Make a Multilingual Form; 11.15 Use Form Inheritance; 11.16 Create a Form That Cant Be Moved; 11.17 Make a Borderless Form Movable; 11.18 Save the Size and Location of a Form; 11.19 Synchronize Controls on a Form; 11.20 Create a System Tray Application; 11.21 Apply Windows XP Control Styles; Chapter 12: Printing and Drawing with GDI+; 12.1 Find All Installed Printers; 12.2 Print a Simple Document; 12.3 Print a Document That Has Multiple Pages; 12.4 Print Centered Text; 12.5 Print Wrapped Text; 12.6 Print from a File; 12.7 Display a Dynamic Print Preview; 12.8 Retrieve Print Queue Information; 12.9 Manage Print Jobs; 12.10 Find All Installed Fonts; 12.11 Convert the Format of an Image; 12.12 Paint Static Content; 12.13 Paint Dynamic Content; 12.14 Use System Colors; 12.15 Improve the Rendering Quality; 12.16 Perform Hit Testing with Shapes; 12.17 Draw Picture Thumbnails; 12.18 Use Double Buffering to Increase Redraw Speed; 12.19 Display an Irregularly Shaped Window; 12.20 Create an Owner-Drawn Menu; 12.21 Create an Owner-Drawn List Box; Chapter 13: Windows Services; 13.1 Use a Windows Service with a Timer; 13.2 Use a Windows Service with a Thread; 13.3 Create a Windows Service Installer; 13.4 Debug a Windows Service; 13.5 Retrieve Information About Installed Windows Services; 13.6 Start and Stop a Windows Service Programmatically; 13.7 Interact with Windows Services on Another Computer; 13.8 Create a Windows Service That Uses a System Tray Icon; Chapter 14: ADO.NET; 14.1 Use Connection Pooling; 14.2 Retrieve the Unique ID for a New Record; 14.3 Retrieve the Unique ID for a New Record in a DataSet; 14.4 Protect Against SQL Injection Attacks; 14.5 Execute Multiple SQL Statements at Once; 14.6 Use Column and Table Mappings; 14.7 Use Last-In-Wins Concurrency with the DataAdapter; 14.8 Optimize DataAdapter Performance with a Timestamp; 14.9 Handle DataAdapter Concurrency Errors; 14.10 Use a Transaction with the DataAdapter; 14.11 Read Large Binary Fields Efficiently with a DataReader; 14.12 Select a Subset of Data from a DataSet; 14.13 Create a Custom Record Browser; 14.14 Filter or Sort Data with a DataView; 14.15 Create a Master-Details Form; 14.16 Format Data-Bound Fields; 14.17 Bind an Image Field to a PictureBox; 14.18 Bind a Field to a List Control, and Restrict It to the Values from Another Table; 14.19 Create a Calculated Column That Uses a Relationship; 14.20 Create a Typed DataSet; 14.21 Read an Excel File with ADO.NET; Chapter 15: ASP.NET Web Applications; 15.1 Enable Web Site Debugging; 15.2 Store Information Between Requests; 15.3 Add Line Breaks to a Label Control; 15.4 Use JavaScript to Handle Key Presses, Mouse Movements, and More; 15.5 Programmatically Set Control Focus; 15.6 Upload a File; 15.7 Use Custom Error Pages; 15.8 Use Forms Authentication; 15.9 Validate User Input; 15.10 Use Page or Fragment Caching; 15.11 Store Arbitrary Data in the ASP.NET Cache; 15.12 Add Controls to a Web Form Dynamically; 15.13 Load User Controls Programmatically; 15.14 Dynamically Generate an Image; 15.15 Dynamically Generate an Image on Part of a Page; 15.16 Use the Internet Explorer Controls; 15.17 Use a Dynamic Menu Control; Chapter 16: Web Services; 16.1 Avoid Hard-Coding the Web Service URL; 16.2 Add Response Caching; 16.3 Add Data Caching; 16.4 Create a Transactional Web Method; 16.5 Create a One-Way Web Method; 16.6 Set Authentication Credentials for a Web Service; 16.7 Use Session State; 16.8 Upload or Download Large Binary Data; 16.9 Send Out-of-Band Data in a SOAP Header; 16.10 Trace a SOAP Message Using the SOAP Toolkit; 16.11 Log SOAP Messages with a SOAP Extension; 16.12 Call a Web Service from a Visual Basic 6 Client; Chapter 17: Remoting and Enterprise Services; 17.1 Make an Object Remotable; 17.2 Register All the Remotable Classes in an Assembly; 17.3 Host a Remote Object in IIS; 17.4 Fire an Event over a Remoting Channel; 17.5 Access a Remote Object Through an Interface; 17.6 Control the Lifetime of a Remote Object; 17.7 Use a Sponsor to Keep Remote Objects Alive; 17.8 Control Versioning for Remote Objects; 17.9 Use a One-Way Method; 17.10 Track Multiple Clients with a Singleton; 17.11 Create a COM+ Serviced Component; 17.12 Prevent Duplicate Entries for Serviced Components; 17.13 Create a Pooled Component; 17.14 Use a COM+ Distributed Transaction; 17.15 Write to the Windows Event Log; 17.16 Find All the Message Queues on a Computer; 17.17 Send a Custom Message Object Through Message Queuing; 17.18 Use a Custom Performance Counter; Chapter 18: Security and Cryptography; 18.1 Retrieve Information About the Current Windows User; 18.2 Use Windows Role-Based Security; 18.3 Retrieve a List of All Windows Accounts or Groups; 18.4 Log In to Another Account Programmatically; 18.5 Impersonate the IIS User with ASP.NET; 18.6 Use SSL Encryption with ASP.NET; 18.7 Symmetrically Encrypt a File; 18.8 Symmetrically Encrypt Any Data; 18.9 Derive a Key from a Password; 18.10 Asymmetrically Encrypt Data; 18.11 Combine Asymmetric and Symmetric Encryption; 18.12 Encrypt an Object; 18.13 Verify That Data Hasnt Changed; 18.14 Create a Tamper-Proof Hash Code; 18.15 Create an XML Digital Signature; 18.16 Store a Salted Password Hash in a Database; 18.17 Generate a Secure Random Number; 18.18 Generate a Secure Random GUID; 18.19 Determine the Evidence Associated with an Assembly; 18.20 Programmatically Restrict Code Permissions; Chapter 19: Useful COM Interop; 19.1 Use ADO Classic; 19.2 Display a Web Page with Internet Explorer; 19.3 Drive Internet Explorer; 19.4 Drive Microsoft Word; 19.5 Drive Microsoft Excel; 19.6 Use MAPI to Send E-Mail Messages; 19.7 Play Media Files; 19.8 Use Masked Text Boxes; Appendix : About the Author;