p. 2
published by microsoft press a division of microsoft corporation one microsoft way redmond washington 98052-6399 copyright © 2006 by tony northrup shawn wildermuth bill ryan and grandmasters llc all rights reserved no part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher isbn-13 978-0-7356-2277-7 isbn-10 0-7356-2277-9 library of congress control number 2006924468 printed and bound in the united states of america 1 2 3 4 5 6 7 8 9 qwt 1 0 9 8 7 6 distributed in canada by h.b fenn and company ltd a cip catalogue record for this book is available from the british library microsoft press books are available through booksellers and distributors worldwide for further information about international editions contact your local microsoft corporation office or contact microsoft press international directly at fax 425 936-7329 visit our web site at www.microsoft.com/mspress send comments to tkinput@microsoft.com microsoft active directory excel intellisense internet explorer microsoft press msdn opentype outlook visual basic visual c visual studio win32 windows windows server and windows vista are either registered trademarks or trademarks of microsoft corporation in the united states and/or other countries other product and company names mentioned herein may be the trademarks of their respective owners the example companies organizations products domain names e-mail addresses logos people places and events depicted herein are fictitious no association with any real company organization product domain name e-mail address logo person place or event is intended or should be inferred this book expresses the author s views and opinions the information contained in this book is provided without any express statutory or implied warranties neither the authors microsoft corporation nor its resellers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book acquisitions editor ken jones project editor laura sackerman technical editors jim fuchs and david robinson indexers lee ross and tony ross body part no x12-41817
[close]
p. 3
for sandi edson tony northrup to my mother pennie wildermuth shawn wildermuth to my parents walter and carole converse for always being there for me to kim and sarah finleyson for putting up with me always being busy and keeping me smiling finally to walter bellhaven and herb sewell for helping me maintain my sanity for the past year bill ryan
[close]
p. 5
about the authors tony northrup in the mid 1980s tony northrup cispp mcse and mvp learned to program in basic on a zx-81 personal computer built from a kit later he mastered the 68000 assembly and ansi c on the motorola versados operating system before beginning to write code for ms-dos after a brief time with the nextstep operating system tony returned to a microsoft platform because he was impressed by the beta version of microsoft windows nt 3.1 although he has dabbled in other operating systems tony has since focused on windows development in microsoft visual c visual basic c and perl for automation projects tony now develops almost exclusively for the .net framework tony started writing in 1997 and has since published more than a dozen technology books on the topics of development and networking in addition tony has written dozens of articles at http www.microsoft.com covering topics ranging from securing asp.net applications to designing firewalls to protect networks and computers tony spends his spare time hiking through the woods near his phillipston massachusetts home he s rarely without his camera and in the past six years has created what might be the largest and most popular publicly accessible database of nature and wildlife photographs on the internet tony lives with his wife erica and his cat also his favorite photographic subject sammy shawn wildermuth shawn wildermuth is a microsoft c mvp and is the founder of wildermuth consulting services llc a company that is dedicated to delivering software and training solutions in the atlanta georgia area he is also a speaker on the ineta speaker bureau and has appeared at several national conferences to speak on a variety of subjects shawn is also the author of the book pragmatic ado.net as well as the upcoming prescriptive data architectures both for addison-wesley he has been writing articles for a number
[close]
p. 6
of years for a variety of magazines and web sites including msdn msdn online devsource informit windows it pro the serverside .net ondotnet.com and intel s rich client series shawn has enjoyed building data-driven software for more than 20 years bill ryan bill ryan is a senior software developer at infopro inc a large medical records management company in augusta ga bill is a microsoft mvp in the windows embedded category bill is also the co-author of professional ado.net 2 and professional winfx beta both by wrox press he s currently authoring professional microsoft speech server by apress bill is a frequent speaker at events such as microsoft code camps speech server days and .net user s groups he also runs two .net focused web sites www.devbuzz.com and www.knowdotnet.com.
[close]
p. 7
contents at a glance 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 framework fundamentals .1 input/output i/o 67 searching modifying and encoding text 143 collections and generics 185 serialization 267 graphics 319 threading 367 application domains and services 435 installing and configuring applications 477 instrumentation 551 application security 627 user and data security 701 interoperation 783 reflection 829 mail 889 globalization 919 vii
[close]
p. 9
table of contents introduction xxxi hardware requirements xxxi software requirements xxxii using the cd and dvd xxxii how to install the practice tests xxxiii how to use the practice tests xxxiii how to uninstall the practice tests xxxiv microsoft certified professional program xxxv technical support xxxv evaluation edition software support xxxvi 1 framework fundamentals .1 before you begin 2 lesson 1 using value types 3 built-in value types 3 how to declare value types 6 how to create user-defined types 7 how to create enumerations 10 lab declaring and using value types 11 lesson summary 14 lesson review 15 lesson 2 using common reference types 17 what is a reference type 17 comparing the behavior of reference and value types 17 built-in reference types 19 strings and string builders 19 how to create and sort arrays 21 how to use streams 22 how to throw and catch exceptions 23 lab working with reference types 25 lesson summary 30 lesson review 30 what do you think of this book we want to hear from you microsoft is interested in hearing your feedback about this publication so we can continually improve our books and learning resources for you to participate in a brief online survey please visit www.microsoft.com/learning/booksurvey ix
[close]
p. 10
x contents lesson 3 constructing classes what is inheritance what is an interface what are partial classes what are generics events what are attributes what is type forwarding lab create a derived class with delegates lesson summary lesson review lesson 4 converting between types conversion in visual basic and c what is boxing and unboxing how to implement conversion in custom types lab safely performing conversions lesson summary lesson review chapter review chapter summary key terms case scenario case scenario designing an application suggested practices manage data in a .net framework application by using .net framework 2.0 system types implement .net framework interfaces to cause components to comply with standard contracts control interactions between .net framework application components by using events and delegates take a practice test 32 32 34 38 38 44 47 48 49 52 52 54 54 56 56 59 60 61 62 62 63 63 64 64 64 65 65 65 2 input/output i/o 67 before you begin lesson 1 navigating the file system what are the file system classes the filesysteminfo class the fileinfo class how to get information about a file how to copy a file 68 69 69 69 70 72 72
[close]
p. 11
contents xi the directoryinfo class 73 how to enumerate files in a directory 74 the driveinfo class 74 the drivetype enumeration 75 how to enumerate drives 76 the path class 77 how to change a file extension 78 the filesystemwatcher class 78 how to monitor a directory for changes 80 lab enumerate files and watch for changes 83 lesson summary 86 lesson review 86 lesson 2 reading and writing files 88 understanding streams 88 what classes facilitate reading and writing data 90 the file class 91 the directory class 92 the fileaccess enumeration 94 the filemode enumeration 94 the filestream class 95 the streamreader class 97 how to read from a file 97 the streamwriter class 100 how to write to a file 100 understanding readers and writers 102 the memorystream class 105 how to use a memorystream 107 the bufferedstream class 108 how to use a bufferedstream 110 lab reading and writing files 111 lesson summary 112 lesson review 113 lesson 3 compressing streams 114 introducing the compression streams 114 the gzipstream class 115
[close]
p. 12
xii contents the deflatestream class how to compress data with a compression stream how to decompress data with a compression stream lab compress and decompress an existing file lesson summary lesson review lesson 4 working with isolated storage what is isolated storage the isolatedstoragefile class how to create a store the isolatedstoragefilestream class reading and writing data to isolated storage how to use directories in isolated storage the isolatedstoragefilepermission class permitting isolated storage lab store and retrieve data from isolated storage lesson summary lesson review chapter review chapter summary key terms case scenarios case scenario 1 saving user settings case scenario 2 monitoring old servers suggested practices create a file searcher application create a simple configuration storage take a practice test 116 118 119 120 124 124 125 125 126 127 129 131 133 134 134 135 137 137 139 139 139 140 140 140 141 141 141 142 3 searching modifying and encoding text 143 before you begin lesson 1 forming regular expressions how to use regular expressions for pattern matching how to extract matched data how to replace substrings using regular expressions how to use regular expressions to constrain string input lab create a regex expression evaluator lesson summary lesson review 144 145 145 158 160 161 163 166 167
[close]
p. 13
contents xiii lesson 2 encoding and decoding 171 understanding encoding 171 using the encoding class 173 how to examine supported code pages 174 how to specify the encoding type when writing a file 175 how to specify the encoding type when reading a file 176 lab read and write an encoded file 177 lesson summary 177 lesson review 178 chapter review 180 chapter summary 180 key terms 180 case scenarios 180 case scenario 1 validating input 181 case scenario 2 processing data from a legacy computer 182 suggested practices 182 enhance the text handling capabilities of a .net framework application and search modify and control text within a .net framework application by using regular expressions 182 take a practice test 183 4 collections and generics 185 before you begin 186 lesson 1 collecting data items 187 types of collections 187 adding and removing items 188 iterating over items 191 consistent interfaces in collections 194 sorting items 195 lab sort a table of strings 197 lesson summary 199 lesson review 199 lesson 2 working with sequential lists 201 what are sequential lists 201 the queue class 201 the stack class 203 lab building fifo and lifo lists 205 lesson summary 207 lesson review 208
[close]
p. 14
xiv contents lesson 3 working with dictionaries using a dictionary understanding equality using the iequalitycomparer interface using the sortedlist class specialized dictionaries lab create a lookup table lesson summary lesson review lesson 4 using specialized collections working with bits collecting strings the namevaluecollection class lab a case-insensitive localizable lookup table lesson summary lesson review lesson 5 generic collections how generics work improving safety and performance generic collection class structure lab create and use a generic collection lesson summary lesson review chapter review chapter summary key terms case scenarios case scenario 1 use an arraylist to store status codes case scenario 2 select the correct collection case scenario 3 rewrite to use a type-safe collection suggested practices use the generic collections compare dictionary classes take a practice test 209 209 213 215 218 220 223 225 225 226 226 232 235 238 239 239 241 241 246 255 259 260 260 262 262 262 262 263 263 264 264 264 265 265 5 serialization 267 before you begin 268 lesson 1 serializing objects 269 what is serialization 269
[close]
p. 15
contents xv how to serialize an object 270 how to deserialize an object 272 how to create classes that can be serialized 274 choosing a serialization format 279 how to use soapformatter 279 how to control soap serialization 280 guidelines for serialization 281 lab serialize and deserialize objects 281 lesson summary 285 lesson review 286 lesson 2 xml serialization 288 why use xml serialization 288 how to use xml to serialize an object 289 how to use xml to deserialize an object 290 how to create classes that can be serialized by using xml serialization 291 how to control xml serialization 291 how to conform to an xml schema 295 how to serialize a dataset 296 lab using xml serialization 297 lesson summary 300 lesson review 300 lesson 3 custom serialization 302 how to implement custom serialization 302 responding to serialization events 305 how to change serialization based on context 308 how to create a custom formatter 309 lab implement custom serialization 309 lesson summary 311 lesson review 311 chapter review 313 chapter summary 313 key terms 313 case scenarios 314 case scenario 1 choosing a serialization technique 314 questions 314 case scenario 2 serializing between versions 315 questions 315
[close]