ebook img

.NET Programming 10-Minute Solutions PDF

447 Pages·2003·4.479 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview .NET Programming 10-Minute Solutions

4253c00.qxd 10/14/03 11:00 PM Page i .NET Programming 10-Minute Solutions 4253c00.qxd 10/14/03 11:00 PM Page ii 4253c00.qxd 10/14/03 11:00 PM Page iii .NET Programming 10-Minute Solutions A. Russell Jones Mike Gunderloy San Francisco • London 4253c00.qxd 10/14/03 11:00 PM Page iv Associate Publisher: Joel Fugazzotto Acquisitions and Developmental Editor: Tom Cirtin Production Editor: Leslie E.H. Light Technical Editor: Greg Guntle Copyeditor: Liz Welch Compositor: Chris Gillespie, Happenstance Type-O-Rama Graphic Illustrator: Jeff Wilson, Happenstance Type-O-Rama Proofreader: Nancy Riddiough Indexer: Lynnzee Elze Book Designer: Maureen Forys, Happenstance Type-O-Rama Cover Illustrator/Photographer: John Nedwidek, Emdesign Copyright © 2004 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. The author(s) created reusable code in this publication expressly for reuse by readers. Sybex grants readers limited permission to reuse the code found in this publication or its accompanying CD-ROM so long as the author(s) are attributed in any application containing the reusable code and the code itself is never distributed, posted online by electronic transmission, sold, or commercially exploited as a stand-alone product. Aside from this specific exception concerning reusable code, No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy, photograph, magnetic, or other record, without the prior agreement and written permis- sion of the publisher. Library of Congress Card Number: 2003109131 ISBN: 0-7821-4253-2 SYBEX and the SYBEX logo are either registered trademarks or trademarks of SYBEX Inc. in the United States and/or other countries. DevX®, “10-Minute Solutions,” and the 10-Minute Solutions logo are the exclusive trademarks of JupiterMedia Corporation and are used under license. Screen reproductions produced with FullShot 99. FullShot 99 © 1991-1999 Inbit Incorporated. All rights reserved. FullShot is a trademark of Inbit Incorporated. TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer. The author and publisher have made their best efforts to prepare this book, and the content is based upon final release software whenever possible. Portions of the manuscript may be based upon pre-release versions supplied by software manufacturer(s). The author and the pub- lisher make no representation or warranties of any kind with regard to the completeness or accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability, fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly from this book. Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 4253c00.qxd 10/14/03 11:00 PM Page v SOFTWARE LICENSE AGREEMENT: Warranty TERMS AND CONDITIONS SYBEX warrants the enclosed media to be free of physical defects for a period of ninety (90) days after purchase. The Software is not The media and/or any online materials accompanying this book available from SYBEX in any other form or media than that that are available now or in the future contain programs and/or enclosed herein or posted to www.sybex.com. If you discover a text files (the “Software”) to be used in connection with the book. defect in the media during this warranty period, you may obtain a SYBEX hereby grants to you a license to use the Software, subject replacement of identical format at no charge by sending the defec- to the terms that follow. Your purchase, acceptance, or use of the tive media, postage prepaid, with proof of purchase to: Software will constitute your acceptance of such terms. SYBEX Inc. The Software compilation is the property of SYBEX unless other- Product Support Department wise indicated and is protected by copyright to SYBEX or other 1151 Marina Village Parkway copyright owner(s) as indicated in the media files (the “Owner(s)”). Alameda, CA 94501 You are hereby granted a single-user license to use the Software Web: http://www.sybex.com for your personal, noncommercial use only. You may not repro- duce, sell, distribute, publish, circulate, or commercially exploit After the 90-day period, you can obtain replacement media of the Software, or any portion thereof, without the written consent identical format by sending us the defective disk, proof of pur- of SYBEX and the specific copyright owner(s) of any component chase, and a check or money order for $10, payable to SYBEX. software included on this media. Disclaimer In the event that the Software or components include specific SYBEX makes no warranty or representation, either expressed or license requirements or end-user agreements, statements of condi- implied, with respect to the Software or its contents, quality, per- tion, disclaimers, limitations or warranties (“End-User License”), formance, merchantability, or fitness for a particular purpose. In those End-User Licenses supersede the terms and conditions no event will SYBEX, its distributors, or dealers be liable to you or herein as to that particular Software component. Your purchase, any other party for direct, indirect, special, incidental, consequen- acceptance, or use of the Software will constitute your acceptance tial, or other damages arising out of the use of or inability to use of such End-User Licenses. the Software or its contents even if advised of the possibility of such damage. In the event that the Software includes an online By purchase, use or acceptance of the Software you further agree update feature, SYBEX further disclaims any obligation to provide to comply with all export laws and regulations of the United States this feature for any specific duration other than the initial posting. as such laws and regulations may exist from time to time. The exclusion of implied warranties is not permitted by some Reusable Code in This Book states. Therefore, the above exclusion may not apply to you. This The authors created reusable code in this publication expressly for warranty provides you with specific legal rights; there may be reuse by readers. Sybex grants readers limited permission to reuse other rights that you may have that vary from state to state. The the code found in this publication, its accompanying CD-ROM or pricing of the book with the Software by SYBEX reflects the allo- available for download from our website so long as the authors are cation of risk and limitations on liability contained in this agree- attributed in any application containing the reusable code and the ment of Terms and Conditions. code itself is never distributed, posted online by electronic transmis- sion, sold, or commercially exploited as a stand-alone product. Shareware Distribution This Software may contain various programs that are distributed Software Support as shareware. Copyright laws apply to both shareware and ordi- Components of the supplemental Software and any offers associ- nary commercial software, and the copyright Owner(s) retains all ated with them may be supported by the specific Owner(s) of that rights. If you try a shareware program and continue using it, you material, but they are not supported by SYBEX. Information are expected to register it. Individual programs differ on details of regarding any available support may be obtained from the trial periods, registration, and payment. Please observe the Owner(s) using the information provided in the appropriate requirements stated in appropriate files. read.me files or listed elsewhere on the media. Copy Protection Should the manufacturer(s) or other Owner(s) cease to offer sup- The Software in whole or in part may or may not be copy-pro- port or decline to honor any offer, SYBEX bears no responsibility. tected or encrypted. However, in all cases, reselling or redistribut- This notice concerning support for the Software is provided for ing these files without authorization is expressly forbidden except your information only. SYBEX is not the agent or principal of the as specifically provided for by the Owner(s) therein. Owner(s), and SYBEX is in no way responsible for providing any support for the Software, nor is it liable or responsible for any sup- port provided, or not provided, by the Owner(s). 4253c00.qxd 10/14/03 11:00 PM Page vi 4253c00.qxd 10/14/03 11:00 PM Page vii We dedicate this book to all the people who take the time to answer programming questions in newsgroups; who write documentation, technical articles, and books to help people learn; and who, collectively, act as resources to increase the level of expertise in the programming community. —A. Russell Jones To the FlyBabies, who helped keep me sane. —Mike Gunderloy 4253c00.qxd 10/14/03 11:00 PM Page viii Acknowledgments F irst, I want to acknowledge DevX and Sybex, whose joint cooperation made this book possible. I think it’s often difficult for two separate publishing organizations to share con- tent and production costs, so congratulations to everyone in both companies who brought this book concept to fruition. Thanks particularly to Tom Cirtin at Sybex, and to Michael (Mac) McCarthy, Lori Piquet, and Rachel Plut at DevX. This book contains solutions by two authors whose names don’t appear on the cover, so I want to acknowledge Evangelos Petroutsos and Ollie Cornes, whose articles have proven popular and helpful to so many people. I’d like to personally thank my co-author Mike Gunderloy for being brave enough to get involved in the lengthy process of co-authoring a book, and my editors, Leslie H. Light and Liz Welch, who have borne the brunt of the burden for finding and fixing the prose. For the many other people who have a hand in taking this book from concept to publication, you have my sincere appreciation. Finally, but not least, I’d like to thank my wife, Janet, for putting up with yet another book effort. —Russell Jones After writing even a portion of a book, I find that the acknowledgements are a relief: they’re the chance to thank the people who have put up with being a part of the life of an author. So in that vein: thanks to Tom Cirtin and Russell Jones for bringing me into this project; it’s been a lot of fun. Thanks also to my colleagues at MCP Magazine, Hardcore Web Services, and elsewhere, who put up with me being occasionally preoccupied with book deadlines. And of course, thanks to my wonderful wife and two growing children, who give me all the reasons I could ever need to keep plugging away at a career in this nutty industry. Now I promise I’ll make up for some of those late nights I spent writing. —Mike Gunderloy 4253c00.qxd 10/14/03 11:00 PM Page ix Contents Introduction xi Windows Forms Solutions 1 Solution 1 ListBox ItemData Is Gone! 2 Solution 2 Create Owner-Drawn ListBoxes and ComboBoxes 16 Solution 3 Upgrade Your INI Files to XML 28 Solution 4 Build Your Own XML-Enabled Windows Forms TreeView Control 48 General .NET Topics 65 Solution 5 Take Advantage of Streams and Formatters in VB.NET 66 Solution 6 File I/O in VB.NET: Avoid the Compatibility Syntax 80 Solution7 Gain Control of Regular Expressions 86 Solution8 Add Sort Capabilities to Your .NET Classes 100 Solution9 A Plethora of XML Choices 109 Solution10 Where Should I Store That Data? 135 Solution11 Performing the Most-Requested Conversions in .NET 154 Solution12 Building Custom Collections in .NET 170 Solution13 Launching and Monitoring External Programs from VB.NET Applications 186 Solution14 Build a Touch Utility with .NET 200 Solution15 Parse and Validate Command-Line Parameters with VB.NET 212 Solution16 Monitor Data and Files with a Windows Service 234 ASP.NET Solutions 253 Solution17 Creating Custom Configuration Settings in ASP.NET 254 Solution18 Internationalize Your ASP.NET Applications (Part 1 of 2) 265 Solution19 Internationalize Your ASP.NET Applications (Part 2 of 2) 281 Solution20 Managing Focus in Web Forms 294 Solution21 The Missing Message Boxes in ASP.NET 306 4253c00.qxd 10/14/03 11:00 PM Page x x Contents ADO.NET Solutions 325 Solution22 Optimizing and Troubleshooting Database Connections 326 Solution23 Replacing Recordsets with DataSets 336 Solution24 Working with Typed DataSets 347 Solution25 Saving Time with Calculated DataColumns 353 Solution26 Combining Tables in a DataSet 360 Solution27 Getting Customized XML from SQL Server 369 Solution28 XML and the DataSet 380 Solution29 DataBinding ListBoxes and ComboBoxes 388 Solution30 Advanced DataBinding 396 Solution31 Synchronizing DataSets with DiffGrams 403 Solution32 The 10-Minute Guide to Paging Data 412 Index 423

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.