3 About the Author Joe Mayo started his software development career in 1986, working on an RCA Spectrum 70 mainframe computer, programming in assembly language where input was via Hollerith card, output was a line printer, and the debugging experience was a light panel where you had to push buttons to load registers and step through commands. Since then, Joe has worked with various mini-computers, workstations, and PCs. The operating systems he s worked on include proprietary, UNIX-based, MS-DOS, and Windows. Besides assembly and dozens of scripting languages, Joe has worked professionally with C, C++, VBA, Visual C++, Forte Tool, Java, VB.NET, and C#. In addition to software engineering, he has worked in many positions, including team lead, supervisor, manager (even running a 24 7 computer operations center with over 50 people). Today, Joe runs his own company, Mayo Software, providing custom software development services and specializing in Microsoft.NET technology. He is the author of LINQ Programming (McGraw-Hill Professional, 2008) and other books. Joe is also the recipient of multiple Microsoft MVP awards. You can follow Joe on About the Technical Editor Roy Ogborn has worn almost every hat one time or another during his interesting and continuing career in the Information Technology field. He was systems manager and developer for Texaco Europe Research, Inc., in Moscow, USSR, during the attempted coup. Back in the United States, he has designed and implemented a GIS system for managing oil and gas wells and leases, and has architected and implemented an enterprise workflow system that managed the business process of taking wells from conception to completion. He architected a system for Forest Oil in Denver that linked disparate accounting, lease management, and production tracking systems for business intelligence for senior executives daily and strategic decisions. Recently he architected and designed a SharePoint-, Silverlight-, and CSLA-based greenhouse gas emissions evaluation, prediction, and decision tool for a multinational environmental engineering firm using the new Visual Studio 2010 Architecture Edition tools. Roy is an independent software architect consultant in the Denver Metro Area specializing in custom solutions that leverage SharePoint. In January 2010 he presented SharePoint 2010 for Developers at the Denver Visual Studio.NET User Group.
4 Microsoft Visual 2010 Studio A Beginner s Guide Joe Mayo New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto
6 To my son, Kamo.
7 This page intentionally left blank
8 Contents at a Glance PART I Understanding Visual Studio 2010 Essentials 1 Introducing Visual Studio Learning Just Enough C# or VB.NET: Basic Syntax Learning Just Enough C# and VB.NET: Types and Members Learning Just Enough C# and VB.NET: Intermediate Syntax PART II Learning the VS 2010 Environment 5 Creating and Building Projects Debugging with Visual Studio Working with Data PART III Building Programs with VS Building Desktop Applications with WPF Creating Web Applications with ASP.NET MVC vii
9 viii Microsoft Visual Studio 2010: A Beginner s Guide 10 Designing Silverlight Applications Deploying Web Services with WCF PART IV Enhancing the VS 2010 Experience 12 Customizing the Development Environment Extending Visual Studio PART V Appendixes A Introduction to XML B Introduction to XAML Index
10 Contents ACKNOWLEDGMENTS xvii INTRODUCTION xix PART I Understanding Visual Studio 2010 Essentials 1 Introducing Visual Studio What Is Visual Studio 2010 About? Automatically Generated Code Rapid Coding Experience Everything at Your Fingertips Customizability and Extensibility Installing Visual Studio Navigating the Visual Studio 2010 Environment The Menu Toolbar Work Area Toolbox Solution Explorer Status Bar Managing VS Windows Expanding and Collapsing Windows Docking Windows ix
11 x Microsoft Visual Studio 2010: A Beginner s Guide Floating Windows Tabbed Windows Closing and Opening Windows Modifying Environment Settings after Setup Exporting Selected Environment Settings Importing Selected Environment Settings Resetting All Settings Familiarization with Visual Studio Project Types Windows Projects Web Projects Office Projects SharePoint Projects Database Projects Summary Learning Just Enough C# or VB.NET: Basic Syntax Starting a Bare-Bones Project Examining the Code Skeleton The Main Method The Program Class The FirstProgram Namespace An Overview of the VS Code Editor Class and Member Locators Bookmarks Setting Editor Options Saving Time with Snippets Coding Expressions and Statements Making Intellisense Work for You Running Programs Primitive Types and Expressions Enums Branching Statements Loops Summary Learning Just Enough C# and VB.NET: Types and Members Creating Classes Class Syntax Class Inheritance The class Snippet Writing Methods Declaring and Using a Method Declaring Parameters and Passing Arguments
12 Contents xi Returning Data and Using Method Results Method Snippets Coding Fields and Properties Declaring and Using Fields Declaring and Using Properties The Property Snippet Summary Learning Just Enough C# and VB.NET: Intermediate Syntax Understanding Delegates and Events Events Delegates Event, Delegate, and Handler Code Completion Implementing Interfaces Creating an Interface Making Classes Implement the Interface Writing Code That Uses an Interface The interface Snippet Applying Arrays and Generics Coding Arrays Coding Generics Summary PART II Learning the VS 2010 Environment 5 Creating and Building Projects Constructing Solutions and Projects Creating a New Project Navigating the Solution Explorer Examining Property Settings Assembly Name Default Namespace Target Framework Output Type Startup Object Icon and Manifest Assembly Information Referencing Assemblies Adding a.net Assembly Reference Managing Assembly References Referencing Your Own Class Libraries Using Code in Class Libraries
13 xii Microsoft Visual Studio 2010: A Beginner s Guide Compiling Applications Building Solutions/Projects Rebuilding Solutions/Projects Cleaning Solutions/Projects Managing Dependencies and Build Order Managing Compilation Settings Navigating a Project with Class View Using the Class Designer Class Designer Visualization Class Designer Code Generation Summary Debugging with Visual Studio Example Code for This Chapter Development-Time Code Tools Configuring Debug Mode Setting Breakpoints Creating a Breakpoint Customizing a Breakpoint Managing Breakpoints Stepping Through Code Inspecting Application State Locals and Autos Windows Watch Windows The Immediate Window The Call Stack Window The Quick Watch Window Watching Variables with Pin To Source Working with IntelliTrace Solving Problems with VS Debugger A Program with Bugs Finding the Bug Fixing the First Bug Debugging and Resolving NullReferenceException Problems Summary Working with Data Working with Databases Introduction to Server Explorer Creating a Database Adding Tables Relating Tables with Foreign Keys Adding Stored Procedures Configuring Database Options
14 Contents xiii Learning Language Integrated Query (LINQ) Querying Object Collections with LINQ Creating a LINQ Projection with Anonymous Types Using LINQ to Sort Collection Results Handling Data with LINQ to SQL Setting Up LINQ to SQL Working with the LINQ to SQL Designer Introduction to Querying LINQ to SQL Performing Queries on Multiple Tables Inserting Data with LINQ to SQL Updating Data with LINQ to SQL Deleting Data with LINQ to SQL Summary PART III Building Programs with VS Building Desktop Applications with WPF Starting a WPF Project Understanding Layout Grid Layout StackPanel Layout DockPanel Layout WrapPanel Layout Canvas Layout Using WPF Controls Managing Windows for Controls Setting Properties Handling Events Coding Event Handlers Working with Data in WPF Setting Up a Data Source Configuring a ComboBox Reading and Saving Data Using the DataGrid Summary Creating Web Applications with ASP.NET MVC Understanding ASP.NET MVC Starting an ASP.NET MVC Project Creating the Models Building Controllers Displaying Views Looking Inside a View Organizing View Files
15 xiv Microsoft Visual Studio 2010: A Beginner s Guide Assigning MasterPage Files Partial Views (a.k.a. User Controls) Managing Routing Building a Customer Management Application Creating a Repository Creating a Customer Controller Displaying a Customer List Adding a New Customer Updating Existing Customers Deleting a Customer Summary Designing Silverlight Applications Starting a Silverlight Project Navigating the Silverlight Designer Using Silverlight Controls Running Silverlight Out-of-Browser (OOB) Deploying Silverlight Applications Summary Deploying Web Services with WCF Starting a WCF Project Specifying a Contract with WCF Interfaces Implementing Logic with WCF Classes Hosting a WCF Service Following General Hosting Procedures Installing IIS 7 on Windows Creating a Web Site on IIS 7 on Windows Deploying the WCF Service to IIS Communicating with a WCF Service Creating a Service Reference Coding Web Service Calls Deploying a Client That Consumes a Web Service Creating a Web Service in a Web Site Summary PART IV Enhancing the VS 2010 Experience 12 Customizing the Development Environment Implementing Custom Templates Creating New Project Templates Creating New Item Templates Creating Custom Snippets Creating a New Snippet Managing the Snippet Library
16 Contents xv Writing Macros Recording a Macro Saving a Macro Editing Macros Summary Extending Visual Studio Creating a Visual Studio Add-In Running the Add-In Project Wizard Examining an Add-In Wizard Solution Drilling into the Connect Class Adding Functionality to an Add-In Reviewing the OnConnection Method Implementing the Exec Method Setting Status with QueryStatus Deploying an Add-In Where to Go Next Summary PART V Appendixes A Introduction to XML VS 2010 XML Editor XML Prefixes XML Elements Attributes Namespaces The XML Menu Configuring XML Options Summary B Introduction to XAML Starting a WPF Project Elements as Classes Attributes as Properties Executing the XAML Document Property Elements Markup Extensions Summary Index
17 This page intentionally left blank
18 Acknowledgments A work of this magnitude is never the ramblings of a single author, but a successful combination of dedication from a team of highly skilled professionals. I would like to personally thank several people who helped make this book possible. Jane Brownlow, Executive Editor, helped kick off the book and got it started on the right path. Megg Morin, Acquisitions Editor, took the reins from Jane and led the rest of the way. Joya Anthony, Acquisitions Coordinator, helped keep the flow of chapters moving. Madhu Bhardwaj, Project Manager, and Patty Mon, Editorial Supervisor, helped coordinate copy edits and final layout. I would really like to thank you all for your patience and assistance. There are many more people at McGraw-Hill who helped put this book together, and I am appreciative of their contributions and professionalism. Roy Ogborn was the technical editor for this book. I ve known Roy for several years and was delighted when he agreed to tech edit the book. Besides catching many of my errors, Roy provided valuable insight that made a difference in several areas, continuously asking the question of whether a beginner would understand a concept, what is the proper application of the language to accomplish a goal, and perspective on what parts of a technology needed emphasis. Thanks to Roy for outstanding technical editing and advice. xvii
19 This page intentionally left blank
20 Introduction V isual Studio has been the primary integrated development environment (IDE) for Microsoft software development for several years. Visual Studio 2010 (VS), the subject of this book, is therefore a mature evolution, building upon the success of its predecessors. This book will show you how to leverage Visual Studio 2010 to your advantage, increasing your skill set, and helping you become more productive in building software. The software you will learn to write will be for.net (pronounced Dot Net ), which is a Microsoft platform for writing different types of applications. As the title suggests, this is a book for beginners. However, there are many opinions about who a beginner is, so let s discuss what beginner means in the context of this book. You should probably have some understanding of what programming is from a general perspective. It would help to have at least written a batch file, macro, or script that instructed the computer to perform some task. A beginner could also be someone who has written software with technology, such as Cobol, Dreamweaver, or Java, but who is unfamiliar with Visual Studio. Whatever your background, this book provides a gradual on-ramp to developing applications with Visual Studio xix
SYMANTEC ServiceDesk Customization Guide 7.0 Symantec ServiceDesk 7 The software described in this book is furnished under a license agreement and may be used only in accordance with the terms of the agreement.
User Guide and Reference Manual Version 3.1 September 2014 Scientific Toolworks, Inc. 53 N Main St. George, UT 84770 Copyright 2014 Scientific Toolworks, Inc. All rights reserved. The information in this
Working Smarter with MS Outlook 2010 Useful Website: https://intranet.uow.edu.au/myit/services/email/ Contents What s new and working smarter with Office 2010... 4 What s new in Office 2010... 6 Tips...
Yosemite Server Backup User s Guide Part number: First edition: October 2010 Legal and notice information Copyright 2004, 2012 Barracuda Networks, Inc. Under copyright laws, the contents of this document
User s Guide L EGAL NOTICES Copyright 2009 Nuance Communications, Inc. All rights reserved. No part of this publication may be transmitted, transcribed, reproduced, stored in any retrieval system or translated
Microsoft Exchange Server 2013 Configuration & Clients William R. Stanek Author and Series Editor Pocket Consultant PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond,
Start Developing ios Apps Today Contents Introduction 6 Setup 7 Get the Tools 8 Review a Few Objective-C Concepts 9 Objects Are Building Blocks for Apps 9 Classes Are Blueprints for Objects 9 Objects Communicate
Canto Cumulus 5.5 Workgroup Edition Administrator Guide An administrator s guide to the Canto Cumulus Digital Asset Management System. 290 Division Street, Suite 400 San Francisco, CA 94103 U.S.A. Voice:
ADOBE PHOTOSHOP LIGHTROOM 5 QUICK START GUIDE Victoria Bampton www.lightroomqueen.com/lr5quickstart www.lightroomqueen.com 1 LEGAL NOTICE: 2013 Victoria Bampton. All rights reserved This ebook is available
About the Author Jean Paul V.A is a Software Developer working on Microsoft Technologies for the past 10 years. He has been passionate about programming and mentored lots of developers on.net and related
CHAPTER Managing Outlook Folders In this chapter Understanding How Outlook Stores Information 40 Using the Navigation Pane and Folder List 44 Using and Managing Folders 52 Understanding Folder Properties
Getting Started Guide StarTeam Borland Software Corporation 100 Enterprise Way Scotts Valley, California 95066-3249 www.borland.com Borland Software Corporation may have patents and/or pending patent applications
Telecommunication Systems Division Title Page Strata Call Manager User Guide September 2010 Publication Information Toshiba America Information Systems, Inc. Telecommunication Systems Division Publication
Product Overview for Windows Small Business Server 2011 December 2010 Abstract Microsoft offers Windows Small Business Servers as a business solution for small businesses by providing a simplified setup,
AVG Internet Security 2015 User Manual Document revision 2015.33 (16.6.2015) C opyright AVG Technologies C Z, s.r.o. All rights reserved. All other trademarks are the property of their respective owners.
Dell Archive Manager 5.1.1 2014 Dell Inc. ALL RIGHTS RESERVED. This guide contains proprietary information protected by copyright. The software described in this guide is furnished under a software license
Getting Started with SharePoint Online for Small Business By Robert Crane Computer Information Agency http://www.ciaops.com Terms This Guide from the Computer Information Agency is provided as is. Every
Campaigner User Guide 2011 j2 Global Canada, Inc. All Rights Reserved. Version 12.3 While every attempt has been made to ensure that the information in this document is accurate and complete, some typographical
Liebert Nform Infrastructure Monitoring Software User Manual - Version 4 TABLE OF CONTENTS 1.0 ABOUT LIEBERT NFORM................................................1 1.1 How Do You Contact Emerson Network
Cumulus 8.1 Administrator Guide Copyright 2010, Canto GmbH. All rights reserved. Canto, the Canto logo, the Cumulus logo, and Cumulus are registered trademarks of Canto, registered in the U.S. and other
Software used by portions of this application require the following license statement: [The BSD License] Copyright (c) 2004-2011 Jaroslaw Kowalski email@example.com All rights reserved. Redistribution
SuccessFactors Admin: Recruiting Management Admin Guide v1204 (One Admin) For SuccessFactors v12 (One Admin) Last Modified 07/17/2012 2012 SuccessFactors, Inc. All rights reserved. Execution is the Difference
Programming from the Ground Up Jonathan Bartlett Edited by Dominick Bruno, Jr. Programming from the Ground Up by Jonathan Bartlett Edited by Dominick Bruno, Jr. Copyright 2003 by Jonathan Bartlett Permission