Page 2 - A Beginner’s Guide
Microsoft ® Visual Studio ® 2010 A Beginner’s Guide
Page 3 - About the Author; About the Technical Editor
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...
Page 7 - This page intentionally left blank
Page 8 - vii; Contents at a Glance
vii Contents at a Glance PART I Understanding Visual Studio 2010 Essentials 1 Introducing Visual Studio 2010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Learning Just Enough C# or VB.NET: Basic Syntax . . . . . . . . . . . . . . . . . . . . . 35 3 Learni...
Page 9 - viii; Microsoft Visual Studio 2010: A Beginner’s Guide
viii Microsoft Visual Studio 2010: A Beginner’s Guide 10 Designing Silverlight Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 11 Deploying Web Services with WCF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 PART IV...
Page 10 - ix; Contents
ix Contents ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiINTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix P...
Page 12 - xi
Returning Data and Using Method Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Method Snippets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Coding Fields and Properties . . . . . . . ...
Page 13 - xii
xii Microsoft Visual Studio 2010: A Beginner’s Guide Compiling Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Building Solutions/Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
Page 14 - xiii
Learning Language Integrated Query (LINQ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Querying Object Collections with LINQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194Creating a LINQ Projection with Anonymous Types . . . . . ....
Page 15 - xiv
xiv Microsoft Visual Studio 2010: A Beginner’s Guide Assigning MasterPage Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258Partial Views (a.k.a. User Controls) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
Page 16 - xv
Contents xv Writing Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Recording a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
Page 18 - xvii; Acknowledgments
xvii 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...
Page 20 - xix; Introduction
xix 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 y...
Page 21 - xx
xx Microsoft Visual Studio 2010: A Beginner’s Guide This book has 13 chapters and is divided into four parts and a couple of appendixes as reference material. The following provides an overview of each section: ● Part I: Understanding Visual Studio 2010 Essentials Chapter 1 begins with an explanatio...
Page 22 - xxi
Introduction xxi Extensible Markup Language (XML) called XML Application Markup Language (XAML). Considering that this is a beginner’s book, I added a couple of appendixes that cover XML and XAML. I recommend that you read the appendixes before reading Chapters 8 and 10. Additionally, you should rea...
Page 24 - Par t
Par t I Understanding Visual Studio 2010 Essentials
Page 26 - Chapter
Page 27 - Key Skills & Concepts; Learn What Visual Studio 2010 Can Do for You; What Is Visual Studio 2010 About?; Automatically Generated Code
4 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Learn What Visual Studio 2010 Can Do for You ● Install and Choose Among Installation Options ● Understand What Types of Applications You Can Build Y our first experience with Visual Studio (VS) 2010 is often installation....
Page 28 - Chapter 1: Introducing Visual Studio 2010; Rapid Coding Experience; Everything at Your Fingertips
Chapter 1: Introducing Visual Studio 2010 5 automatically generated code. VS offers many premade controls, which include skeleton code, saving you from having to write your own code for repetitive tasks. Many of the more complex controls contain wizards that help you customize the control’s behavior...
Page 29 - Installing Visual Studio 2010; System Requirements
6 Microsoft Visual Studio 2010: A Beginner’s Guide Installing Visual Studio 2010 Hopefully the preceding discussion whets your appetite on what VS can do for you. If you haven’t already installed VS, this section walks you through the setup process. The guidance along the way will explain how to cho...
Page 36 - Navigating the Visual Studio 2010 Environment
Chapter 1: Introducing Visual Studio 2010 13 The choice you make for default environment settings depends a lot on what language or environment you’ll use to write software in. The environment settings choice isn’t locked in stone and can be reset if you decide you don’t like the settings. A later s...
Page 37 - The Menu
14 Microsoft Visual Studio 2010: A Beginner’s Guide The Menu At the very top left of Figure 1-10, you’ll see the menu bar, which includes the words “File,” “Edit,” “View,” “Tools,” and so on. The menu bar is a standard part of most windows applications. Besides standard file management functionality...
Page 38 - Toolbar
Chapter 1: Introducing Visual Studio 2010 15 The Tools menu contains a grab-bag of functionality; for instance, you can attach a debugger to see your other programs run, line by line; connect to a database for data; set add-ins, macros, and more. One very important menu item on the Tools menu is Opt...
Page 39 - Toolbox; Managing VS Windows
16 Microsoft Visual Studio 2010: A Beginner’s Guide Toolbox On the far left side of Figure 1-10 is a vertical tab, titled Toolbox, which contains a context-sensitive list of controls that can be dragged and dropped onto the current designer surface. The term “context-sensitive” means that certain it...
Page 40 - Expanding and Collapsing Windows
Chapter 1: Introducing Visual Studio 2010 17 Expanding and Collapsing Windows Hovering over the Toolbox tab will expand the Toolbox and display a set of three icons in the title bar of the Toolbox window: Window Position (down arrow), Hide (pin), and Close (cross). You can see what the Toolbox windo...
Page 41 - Docking Windows
18 Microsoft Visual Studio 2010: A Beginner’s Guide If you move the carat away from the Toolbox, the Toolbox will collapse and turn back into a tab on the left side of the screen. For any collapsed window, such as the Toolbox, you can expand that collapsed window and click the Hide (pin) icon to pin...
Page 42 - Floating Windows
Chapter 1: Introducing Visual Studio 2010 19 As shown in Figure 1-14, you’ll see a visual set of icons appear over the workspace, indicating the docking zones where you can move the window to. The shadow of the window will show what the new location will be whenever you drag a window into a docking ...
Page 43 - Tabbed Windows; TIP
20 Microsoft Visual Studio 2010: A Beginner’s Guide Tabbed Windows An example of using the Dock As Tabbed Document option is the Start page. Any window set as Dock As Tabbed Document will appear as a new tab in the work area, along with all the other windows set as Dock As Tabbed Document. For examp...
Page 44 - Closing and Opening Windows
Chapter 1: Introducing Visual Studio 2010 21 Closing and Opening Windows Clicking the Close icon on a window title bar will close the window. Another way to close the window is by selecting the Hide option from the Window Position icon menu. Reopening a window depends on what type of window it is: V...
Page 45 - Modifying Environment Settings after Setup
22 Microsoft Visual Studio 2010: A Beginner’s Guide Modifying Environment Settings after Setup Reasons for modifying environment settings include wanting to reset everything back to a default, importing shared settings from another developer, or switching between settings for different projects. Thi...
Page 46 - Exporting Selected Environment Settings
Chapter 1: Introducing Visual Studio 2010 23 Exporting Selected Environment Settings We’ll start off with export, which you might use to share your settings with another developer. This could also be useful if you planned to make significant changes to your settings and wanted a backup in case you w...
Page 47 - Importing Selected Environment Settings
24 Microsoft Visual Studio 2010: A Beginner’s Guide The two text boxes in Figure 1-19 are for a filename and path where the settings file will be saved. Notice that the default filename includes the date, which could be helpful if you ever need to restore settings. Click Finish, which will perform t...
Page 51 - Resetting All Settings
28 Microsoft Visual Studio 2010: A Beginner’s Guide Your import is now complete, and you can click the Close window. Another settings option is to reset your current settings to one of the VS default options, explained next. Resetting All Settings You could reset settings if you wanted to restore th...
Page 53 - Familiarization with Visual Studio Project Types; NOTE
30 Microsoft Visual Studio 2010: A Beginner’s Guide Familiarization with Visual Studio Project Types Visual Studio includes a plethora of project types, making it easy to build applications with premade templates. The following discussion will show how to find what project types are available and de...
Page 55 - Windows Projects
32 Microsoft Visual Studio 2010: A Beginner’s Guide earlier in this chapter, the default set of project types would have been VB and C# projects would be listed in the Other Languages branch. The following sections describe the types of projects available, some of which you’ll learn how to create la...
Page 56 - Web Projects
Chapter 1: Introducing Visual Studio 2010 33 Other windows projects include Windows Services, which are applications that are always on and run as a service in the background without a GUI, Class Libraries for holding reusable code often referred to as middleware, and Control Libraries for holding g...
Page 57 - Office Projects; Summary
34 Microsoft Visual Studio 2010: A Beginner’s Guide Office Projects For years, developers have been writing Visual Basic for Applications (VBA) programs to automate Microsoft Office applications. An Office project allows you to automate Office applications through .NET using languages such as VB and...
Page 59 - Learn Basics of Starting a Project; Starting a Bare-Bones Project
36 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Learn Basics of Starting a Project ● Use the VS Editor ● Code Expressions and Statements T he .NET platform supports several different programming languages. Since all of the languages run on the same platform and share ...
Page 62 - Examining the Code Skeleton
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 39 into a project depend on the project type. For example, there are project items that are part of a WPF application but wouldn’t be part of a Console application. Of particular interest in the FirstProgram project is the file named Program...
Page 63 - The Main Method
40 Microsoft Visual Studio 2010: A Beginner’s Guide The skeleton code in Listing 2-1 is what VS created when the new Console application was created. It is there to give you a head start on writing your program. What you now have is a whole computer program. This program doesn’t do much of anything ...
Page 64 - The Program Class
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 41 that belong to each instance. If an object such as Customer has methods that belong to each instance, those methods are not static. However, if the Customer object type has a method that is static, then there would only be a single copy o...
Page 65 - The FirstProgram Namespace
42 Microsoft Visual Studio 2010: A Beginner’s Guide which you’ll see many times throughout this book. The Console application defined the skeleton code class to have the name Program. In reality you can name the class anything you want. Whatever names you choose should make sense for the purpose of ...
Page 66 - An Overview of the VS Code Editor
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 43 The using directives at the top of the C# part of Listing 2-1 are really a shortcut that makes it easier for you to write code. For example, the System namespace contains the Console class. If the using System directive were not present, ...
Page 67 - Class and Member Locators
44 Microsoft Visual Studio 2010: A Beginner’s Guide The following sections examine various elements of the Code editor, starting with class and member locators. Class and Member Locators The two drop-down lists, class locator and member locator, at the top of the editor are for navigating the code. ...
Page 68 - Setting Editor Options
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 45 One of the entries in Table 2-1, CTRL - W , B opens the Bookmarks window shown in Figure 2-4, allowing you to manage bookmarks throughout your application. The bookmark has a toolbar, which is the same toolbar that appears in VS when the ...
Page 70 - Saving Time with Snippets
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 47 The Options window in Figure 2-6 is opened to Text Editor, C#, Formatting New Lines. As you can see, there are very detailed settings for even how the editor automatically formats new lines and where braces appear. If the code doesn’t for...
Page 72 - Coding Expressions and Statements; Making Intellisense Work for You
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 49 Coding Expressions and Statements There are various types of statements you can write with both C# and VB, including assignment, method invocations, branching, and loops. We’ll start off by looking at primitive types, such as integers and...
Page 74 - Running Programs
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 51 Notice that there is a text box titled “Committed by typing the following characters,” which contains a set of characters that will cause VS to type the rest of the selected identifier in the completion list plus the character you typed. ...
Page 75 - Primitive Types and Expressions; Primitive Types
52 Microsoft Visual Studio 2010: A Beginner’s Guide To run with debugging, either select Debug | Start Debugging or press F 5 . Because of the way the application is coded so far, the Command Prompt window will quickly run and close; you might miss it if you blink your eyes. To prevent this, you can...
Page 77 - Expressions
54 Microsoft Visual Studio 2010: A Beginner’s Guide Consistent with Table 2-2, C# uses int and VB uses Integer as their native type definitions for a 32-bit signed integer. Additionally, you see age defined in both C# and VB using the .NET type, Int32. Notice that the .NET type is the same in both l...
Page 78 - The Ternary and Immediate If Operators; Enums
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 55 The Ternary and Immediate If Operators The C# ternary and VB immediate if operators allow you to test a condition and return a different value depending on whether that condition is true or false. Listing 2-2 shows how the ternary and imm...
Page 80 - Branching Statements
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 57 The accountType enum variable is a BankAccount and is initialized to have the value of the Checking member of BankAccount. The next statement uses a ternary operator to check the value of accountType, evaluating whether it is Checking. If...
Page 82 - Switch/Select Statements
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 59 As shown in Figure 2-11, the template brings you to a highlighted field for specifying the condition of the if statement. For C#, type the condition you want evaluated and press ENTER ; the snippet completes by placing your carat within t...
Page 83 - Switch Statement Snippets
60 Microsoft Visual Studio 2010: A Beginner’s Guide is required. When the program executes a break statement, it stops executing the switch statement and begins executing the next statement after the last curly brace of the switch statement. For the VB example, the Select Case statement uses name as...
Page 84 - Loops; For
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 61 In C#, you normally just add the case statements you need. However, there is a special feature of the switch snippet that makes it even more efficient to use enums, creating a case for each enum value automatically. In the following examp...
Page 85 - The; For Each Loops
62 Microsoft Visual Studio 2010: A Beginner’s Guide In the preceding C# loop, i is a variable of type int, the loop will continue to execute as long as i is less than 3, and i will be incremented by one every time after the loop executes. The condition, i < 3, is evaluated before the loop execute...
Page 87 - While Loops
64 Microsoft Visual Studio 2010: A Beginner’s Guide While Loops A while loop will allow a block of code to execute as long as a specified condition is true. Here’s an example that does a countdown of numbers: C#: int count = 3; while (count > 0) { Console.WriteLine("count: " + count); cou...
Page 88 - Do Loops; The Do Loop Snippet
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 65 Do Loops You can use a do loop if you want the code in the loop to execute at least one time. Here’s an example that demonstrates a simple menu that obtains user input: C#: string response = ""; do { Console.Write("Press 'Q' a...
Page 91 - Create Classes; Creating Classes; Class Syntax
68 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Create Classes ● Write Methods ● Code Fields and Properties A type is a general term for classes, modules, enums, and more. This chapter will specifically discuss the class type, which allows you to create your own custo...
Page 93 - Class Inheritance
70 Microsoft Visual Studio 2010: A Beginner’s Guide Now that you can define a new class, create an instance from that class, and use it, the next section shows you another feature of classes called inheritance. Class Inheritance One class can reuse the members of another through a feature known as i...
Page 94 - The class Snippet
Chapter 3: Learning Just Enough C# and VB.NET: Types and Members 71 Listing 3-4 Code using inheritance C#: Cashier cashr = new Cashier(); cashr.FirstName = "May"; VB: Dim cashr As New Cashier cashr.FirstName = "May" According to Listing 3-4, Cashier does not have a field named FirstN...
Page 95 - Writing Methods; Declaring and Using a Method
72 Microsoft Visual Studio 2010: A Beginner’s Guide Just type in the class name in the field and press ENTER . The carat will locate to the inside of the class block. Now that you know how to create classes, you’ll need to know how to add members, starting with methods. Writing Methods You can divid...
Page 98 - Declaring Parameters and Passing Arguments
Chapter 3: Learning Just Enough C# and VB.NET: Types and Members 75 Since PrintMethodInstance is an instance method, you call it differently; through an instance of its containing type, which the following code repeats from Listing 3-5: C#: MessagePrinter msgPrint = new MessagePrinter(); msgPrint.Pr...
Page 101 - Returning Data and Using Method Results
78 Microsoft Visual Studio 2010: A Beginner’s Guide VB: Sub PrintCustomerReport( ByVal customers As String(), Optional ByVal title As String = "Customer Report") Console.WriteLine(title) Console.WriteLine() For Each name In customers Console.WriteLine(name) Next End Sub The preceding code re...
Page 103 - Method Snippets
80 Microsoft Visual Studio 2010: A Beginner’s Guide VB (Calc.vb): Public Class Calc Public Function SquareInt(ByVal number As Integer) As Integer Return number * number End Function End Class For the C# example, notice how the return type of the SquareInt method is type int, rather than the keyword ...
Page 104 - Coding Fields and Properties; Declaring and Using Fields
Chapter 3: Learning Just Enough C# and VB.NET: Types and Members 81 Coding Fields and Properties A field is a variable that is a member of a class (type), as opposed to variables that are declared inside of methods, which are called local variables or locally scoped variables. Properties are type me...
Page 106 - Declaring and Using Properties
Chapter 3: Learning Just Enough C# and VB.NET: Types and Members 83 Public Property CurrentBalance() As Decimal Get Return accountBalance End Get Set(ByVal value As Decimal) If value < 0 Then ' charge fee End If accountBalance = value End Set End Property End Module Look at where accountBalance i...
Page 109 - The Property Snippet
86 Microsoft Visual Studio 2010: A Beginner’s Guide Listing 3-10 Auto-implemented properties C#: public string FirstName { get; set; } VB: Public Property FirstName As String The automatic property, FirstName, is logically equivalent to the expanded FirstName with accessors and backing field. Behind...
Page 113 - Use Delegates and Events; Understanding Delegates and Events
90 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Use Delegates and Events ● Implement Interfaces ● Code with Arrays and Generics I n previous chapters, you learned basic syntax and how to create your own types. This chapter rounds out the bare essentials of what you ne...
Page 114 - Events
Chapter 4: Learning Just Enough C# and VB.NET: Intermediate Syntax 91 The next section will add more logic to the set accessor in CurrentBalance in the next listing and raise an event for the calling code. Events An event is a type of class member that allows your class or class instance to notify a...
Page 117 - Delegates
94 Microsoft Visual Studio 2010: A Beginner’s Guide Delegates Delegates let you hook up methods as the receiver to specific events. The delegate specifies the allowable signature, the number of arguments, and their types, of a method that is allowed to be hooked up to the event as a listener or hand...
Page 118 - Event, Delegate, and Handler Code Completion
Chapter 4: Learning Just Enough C# and VB.NET: Intermediate Syntax 95 In the C# example, the += syntax is for assigning a delegate to an event (using a bit of programmer slang, this syntax is commonly said to “wire up an event”). The VB example uses AddHandler and AddressOf to assign the AccountOver...
Page 119 - Implementing Interfaces
96 Microsoft Visual Studio 2010: A Beginner’s Guide As you can see, the Editor pops up a tooltip instructing you to type TAB to create a new delegate instance. Type TAB and Code Completion will pop up another tooltip for creating the handler method, as shown in Figure 4-2. In Figure 4-2, you can see...
Page 120 - Creating an Interface
Chapter 4: Learning Just Enough C# and VB.NET: Intermediate Syntax 97 Creating an Interface To create an interface, right-click the project in Solution Explorer, select Add | New Item, select Code under the language branch in Installed Templates, and select the Interface item. Name the Interface IAc...
Page 121 - Making Classes Implement the Interface
98 Microsoft Visual Studio 2010: A Beginner’s Guide Making Classes Implement the Interface To create a class, right-click the project in Solution Explorer, select Add | New Item, select Code under the language branch in Installed Templates, and select the Class item. Name the class Checking and clic...
Page 124 - Writing Code That Uses an Interface
Chapter 4: Learning Just Enough C# and VB.NET: Intermediate Syntax 101 In the C# listing, following the class name by a colon and then the interface name specifies that the class will implement the interface. The VB listing uses the Implements keyword to indicate that Checking and Saving classes imp...
Page 129 - The interface Snippet
106 Microsoft Visual Studio 2010: A Beginner’s Guide invokes the Credit method on the runtime Checking or Saving instance. Your code that you wrote for Checking.Credit and Saving.Credit will execute as if your code called them directly as in Listing 4-5. Also observe that we’ve eliminated the duplic...
Page 130 - Applying Arrays and Generics; Coding Arrays
Chapter 4: Learning Just Enough C# and VB.NET: Intermediate Syntax 107 Applying Arrays and Generics Whatever code you write will typically need to group objects into a single collection of that object type. For this, you can use an array, which is a container that can have zero or many elements, eac...
Page 132 - Coding Generics
Chapter 4: Learning Just Enough C# and VB.NET: Intermediate Syntax 109 Coding Generics Generics are language features that allow you to write a piece of code that will work with multiple types efficiently. A generic class definition has a placeholder for the type you want it to represent, and you us...
Page 134 - II
Page 137 - Work with Projects and Solutions; Constructing Solutions and Projects
114 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Work with Projects and Solutions ● Set Properties in the Properties Window ● Reference and Use Class Libraries ● Compile and Run Projects ● Use the Class Designer P rojects and solutions are VS’s way of helping you orga...
Page 138 - Chapter 5: Creating and Building Projects; Creating a New Project
Chapter 5: Creating and Building Projects 115 a project inside of a solution. Different project types have unique settings and options, but we’ll start by creating a Console application, which will reduce unnecessary detail and help focus on the common features of all project types. Creating a New P...
Page 139 - Navigating the Solution Explorer
116 Microsoft Visual Studio 2010: A Beginner’s Guide VS will update the Solution Name with the same name. In a multiproject solution, this might not make sense. So, first type the project name and then you can provide a name for the solution that is more appropriate. In Figure 5-1, you can see that ...
Page 141 - Examining Property Settings
118 Microsoft Visual Studio 2010: A Beginner’s Guide solution selected, all you’ll see is the Add A New Solution Folder button, so you’ll need to select a project before the Show All Files button will display. An example of a hidden file is the bin folder hierarchy that contains the output of your p...
Page 142 - Assembly Name; Target Framework
Chapter 5: Creating and Building Projects 119 to all projects. The following sections describe each of the features of the Application settings tab. Assembly Name VS projects create either *.dll or *.exe assemblies. The assembly name provides the filename for this project and defaults to the name of...
Page 143 - Startup Object; Icon and Manifest
120 Microsoft Visual Studio 2010: A Beginner’s Guide TIP If you have a WPF project, its Output Type is set to Windows Application. If you switched the Output Type of a WPF application to Console Application, you would see the Console window appear also. This might be useful for some intermediate deb...
Page 145 - Referencing Assemblies
122 Microsoft Visual Studio 2010: A Beginner’s Guide As you can see in Figure 5-5, the Assembly Information from the project properties is included with the file. This is convenient for you (or an end user) to be able to open the file and read pertinent information, especially version information, t...
Page 146 - Adding a .NET Assembly Reference
Chapter 5: Creating and Building Projects 123 Assembly references are added to a project to tell the compiler where to find the types it is using in an application. When your compiler runs, it will know what types you have in your code and looks through the set of referenced assemblies to find that ...
Page 147 - Managing Assembly References
124 Microsoft Visual Studio 2010: A Beginner’s Guide (GAC), which is a shared repository of assemblies. Microsoft and third parties will place assemblies in the GAC to make it easier to share them by any programs. The COM tab shows all of the COM applications currently registered on your computer. F...
Page 148 - Referencing Your Own Class Libraries
Chapter 5: Creating and Building Projects 125 open the Properties window by double-clicking My Project, click the References tab, select the reference to delete, and click Remove. Figure 5-7 shows the VB References tab. VB includes additional functionality on the References tab. For example, you can...
Page 149 - Using Code in Class Libraries
126 Microsoft Visual Studio 2010: A Beginner’s Guide Within the SolutionDemo solution, we’ll create a new project for a class library. Right-click SolutionDemo and select Add | New Project. This time, select Class Library instead of Console Application and name it ClassLibraryDemo . Clicking OK will...
Page 152 - Compiling Applications; Building Solutions/Projects
Chapter 5: Creating and Building Projects 129 For Each grade In grades Console.WriteLine(" - " & grade) Next Console.ReadKey() End Sub End Module One item to draw your attention to in Listing 5-2 is the using directive ( Imports in VB), specifying that you can use the types in the ClassL...
Page 153 - Rebuilding Solutions/Projects
130 Microsoft Visual Studio 2010: A Beginner’s Guide but projects that are untouched will be reused as is. A build is typically the fastest option during normal development because building only items that are out of date means that there are likely items that don’t need to be built. Be aware, thoug...
Page 154 - Managing Dependencies and Build Order
Chapter 5: Creating and Building Projects 131 Normally, a full rebuild ensures that you have the most up-to-date outputs available. You could also perform a clean operation to ensure all outputs were removed and then perform a build to see which outputs were created. This might give you insight into...
Page 156 - Managing Compilation Settings
Chapter 5: Creating and Building Projects 133 CAUTION Don’t alter project dependencies unless you really know what you are doing. The results could be severe in that it can take a long time to fix dependencies in a large project. The automatic dependency management provided by VS is very dependable,...
Page 159 - Navigating a Project with Class View
136 Microsoft Visual Studio 2010: A Beginner’s Guide Navigating a Project with Class View An alternate way to work with projects is via Class view, which allows you to view solutions and project artifacts through the logical layout of the code. In C#, you can open Class view by pressing CTRL - W , C...
Page 160 - Using the Class Designer; Class Designer Visualization
Chapter 5: Creating and Building Projects 137 Using the Class Designer When working with a project, it can sometimes be helpful to have a high-level view of the project contents, especially if someone else has created the project and you haven’t worked with that project before. This is where the Cla...
Page 161 - Class Designer Code Generation
138 Microsoft Visual Studio 2010: A Beginner’s Guide Class Details window provides additional details on the members of the Program.cs class. Figure 5-13 is a minimal diagram of one class with a single method, Main, and you would have seen all of the classes in the current project if there were more...
Page 167 - Exploring Available Debugging Tools; Example Code for This Chapter
144 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Exploring Available Debugging Tools ● Setting Breakpoints ● Inspecting Program State ● Solving Problems with VS Debugging Tools M ore often than we would like, our code has bugs. Fortunately, when bugs do happen, you ha...
Page 168 - Chapter 6: Debugging with Visual Studio
Chapter 6: Debugging with Visual Studio 145 Listing 6-1 Example code for chapter C#: Program.cs using System; namespace DebugAndTestDemo { class Program { static void Main() { Customer cust = new Customer(); cust.Discount = .1m; Order ord = new Order(); ord.AddItem(5.00m); ord.AddItem(2.50m); cust.O...
Page 171 - Development-Time Code Tools
148 Microsoft Visual Studio 2010: A Beginner’s Guide This program calculates the total monetary discount that a customer would receive for that order by calling the GetOrderDiscount method on the Customer instance, which then returns the calculated discount amount to be subsequently displayed on the...
Page 173 - Configuring Debug Mode
150 Microsoft Visual Studio 2010: A Beginner’s Guide If you’ve been working on your code and want to update the Call Hierarchy window, click Refresh. Every time you view Call Hierarchy, the selected item is added to the list. You can use the Remove Root button to delete an item from the list. The To...
Page 178 - Setting Breakpoints
Chapter 6: Debugging with Visual Studio 155 As you can see in Figure 6-5, there are a variety of options that allow you to configure debugging. The primary difference between project settings and Options settings is that project settings are for that one project, but Options settings let you change ...
Page 179 - Creating a Breakpoint
156 Microsoft Visual Studio 2010: A Beginner’s Guide Creating a Breakpoint To create a breakpoint, you need to open a project and have a code file open in the editor. A good project choice would be the example application with code from Listing 6-1. In the VS editor, there is a margin on the left si...
Page 180 - Customizing a Breakpoint
Chapter 6: Debugging with Visual Studio 157 TIP If you write a program that is doing a lot of work, or very little work but is stuck in an endless loop that you inadvertently created, you can pause execution by selecting the blue pair of vertical bars button found to the left of the square blue stop...
Page 181 - Managing Breakpoints; Stepping Through Code
158 Microsoft Visual Studio 2010: A Beginner’s Guide Figure 6-7 The Breakpoints window Managing Breakpoints Over time, breakpoints can be set across many locations in your project. You can manage all of these breakpoints in a central location by selecting Debug | Windows | Breakpoints, which will sh...
Page 183 - Inspecting Application State; Locals and Autos Windows
160 Microsoft Visual Studio 2010: A Beginner’s Guide Inspecting Application State Application state is the value of variables in your code, the current path of execution, or any other information that tells you what your program is doing. While debugging, it’s important to be able to view applicatio...
Page 184 - Watch Windows
Chapter 6: Debugging with Visual Studio 161 list can be quite long, depending on how many variables are in scope. You would want to use the Locals window to find any variables being affected by the current algorithm. In comparison, Figure 6-9 shows the Autos window. Notice that the Autos window prov...
Page 185 - The Immediate Window
162 Microsoft Visual Studio 2010: A Beginner’s Guide The Locals and Autos windows can sometimes become crowded with too many variables and slow you down as your code gets more complex, especially when the variables you’re interested in are at the bottom of the list or so far apart that you must scro...
Page 186 - The Call Stack Window; The Quick Watch Window
Chapter 6: Debugging with Visual Studio 163 The Call Stack Window If you recall from the previous section on design-time tools, the Call Hierarchy window gives you a view of the code at design time. On a related note, you also have the ability to view the path of execution during runtime via the Cal...
Page 187 - Watching Variables with Pin To Source
164 Microsoft Visual Studio 2010: A Beginner’s Guide the Quick Watch window will show that expression. Figure 6-13 shows the Quick Watch window in use. Clicking the Reevaluate button, shown in Figure 6-13, will show the results of evaluation in the Value area. The Value area will only hold the curre...
Page 188 - Working with IntelliTrace
Chapter 6: Debugging with Visual Studio 165 VS will locate the pinned value after the line, and you might not see the value if it occurs on a long line that exceeds the width of your screen. Fortunately, you can click the pinned value and drag it to where you want on the screen. To avoid confusion, ...
Page 189 - Solving Problems with VS Debugger
166 Microsoft Visual Studio 2010: A Beginner’s Guide IntelliTrace could be useful if you stepped over a statement that changed the value of a variable and needed to go back to see what the variable value was before you stepped. Figure 6-15 shows this scenario, where the highlighted event, Breakpoint...
Page 190 - A Program with Bugs; The Customer Class
Chapter 6: Debugging with Visual Studio 167 handling bad data and fixing null references. The program itself is not particularly sophisticated, but it contains just enough logic to lead you down a rat hole and show you how to work your way out. First, we’ll look at the program, and then we’ll follow...
Page 191 - The CustomerRepository Class
168 Microsoft Visual Studio 2010: A Beginner’s Guide The CustomerRepository Class In this program, we create a class that is solely responsible for working with data. This is a common pattern, which is called the Repository pattern. The following CustomerRepository class has a method that returns a ...
Page 192 - The Program with Bugs
Chapter 6: Debugging with Visual Studio 169 { .FirstName = "Jean " }, New Customer With { .FirstName = "Wim", .LastName = "Meister" } } Return customers End Function End Class The GetCustomers method returns a List<Customer> ( List(Of Customer) in VB). For the purposes ...
Page 194 - Finding the Bug
Chapter 6: Debugging with Visual Studio 171 If (customerFound = False) Then Console.WriteLine("Didn't find customer.") End If Console.ReadKey() End Sub End Module Notice that the searchName variable is set to “Jean”. Within the loop, the searchName is compared with the FirstName property of ...
Page 197 - Fixing the First Bug
174 Microsoft Visual Studio 2010: A Beginner’s Guide representation of the data where any characters that don’t have a readable representation appear as dots. You can see “.J.e.a.n.” on the first line of the third column. .NET characters are 16-bit Unicode, and the data for the character only fills ...
Page 198 - Debugging and Resolving
Chapter 6: Debugging with Visual Studio 175 { Console.WriteLine( "Found: {0} {1}", firstName, lastName); customerFound = true; } VB: Dim firstName As String = cust.FirstName.Trim() Dim lastName As String = cust.LastName.Trim() If (searchName = cust.FirstName) Then Console.WriteLine( "Fou...
Page 204 - Working with Data
Page 205 - Work on SQL Server Databases with Visual Studio 2010; Working with Databases; Introduction to Server Explorer
182 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Work on SQL Server Databases with Visual Studio 2010 ● Query Data with Language Integrated Query (LINQ) ● Use LINQ to SQL to Query and Manipulate SQL Server Data M ost of the work we do each day involves data, and most ...
Page 206 - Chapter 7: Working with Data; Creating a Database
Chapter 7: Working with Data 183 View | Server Explorer or pressing CTRL - ALT - S . Server Explorer, shown in Figure 7-1, allows you to work with databases, servers, and SharePoint. Servers give you access to the various types of services for managing an operating system, such as Event Logs, Perfor...
Page 208 - Adding Tables
Chapter 7: Working with Data 185 Adding Tables The database itself will hold data for customers, orders, and order details that we introduced in the preceding chapter. The data will be held in tables that we’ll create in this section. In later sections, I’ll show you how to perform Create, Read, Upd...
Page 210 - Relating Tables with Foreign Keys
Chapter 7: Working with Data 187 customer data. Notice that you need only type a name in the Name column (replacing the word NULL ) and do not need to enter a value for the CustomerID, since we’ve made the CustomerID column auto-increment. In a database of any sophistication, you have multiple table...
Page 215 - Adding Stored Procedures
192 Microsoft Visual Studio 2010: A Beginner’s Guide copy of the diagram, right-click and copy to clipboard or select File | Print. You can also add multiple diagrams to the Database Diagrams folder, allowing you to have multiple different views for your convenience. In addition to tables and diagra...
Page 216 - Configuring Database Options
Chapter 7: Working with Data 193 To execute this stored procedure, right-click the stored procedure in the database in Server Explorer and click Execute. You’ll see output similar to the following if there are records in the customer table: Running [dbo].[GetCustomers]. Name ------------------------...
Page 217 - Learning Language Integrated Query (LINQ); Querying Object Collections with LINQ
194 Microsoft Visual Studio 2010: A Beginner’s Guide options found after clicking the arrow button to expand Database Tools and then selecting Table And Database Designers is “Prevent saving changes that require table re-creation.” VS will not allow you to save a foreign key change to existing table...
Page 221 - Creating a LINQ Projection with Anonymous Types
198 Microsoft Visual Studio 2010: A Beginner’s Guide Creating a LINQ Projection with Anonymous Types You can customize what is returned by the select clause by using what is called an anonymous type. This customization of return values is called a projection. Anonymous types facilitate custom projec...
Page 222 - Using LINQ to Sort Collection Results
Chapter 7: Working with Data 199 only have a FullName property. Notice how the foreach loop uses the FullName property, instead of the FirstName property from Listing 7-2. The beauty of this anonymous type is that we don’t really care what type of object is generated for us by the LINQ query, as lon...
Page 223 - Handling Data with LINQ to SQL; Setting Up LINQ to SQL
200 Microsoft Visual Studio 2010: A Beginner’s Guide Handling Data with LINQ to SQL The LINQ to SQL provider allows you to communicate with SQL Server databases. There are many other types of providers, such as LINQ to Entities for generic databases (which includes SQL Server), LINQ to XML for XML d...
Page 224 - Working with the LINQ to SQL Designer
Chapter 7: Working with Data 201 To add entities to the LINQ to SQL Designer, open Server Explorer, select a database, and open the Tables folder. Then drag and drop the Customer and Order tables from Server Explorer to the left surface of the LINQ to SQL Designer. You can see the Customer and Order...
Page 226 - Introduction to Querying LINQ to SQL
Chapter 7: Working with Data 203 LINQ to SQL generates a lot of code for you, and the Properties window allows you to modify parts of that code through the Code Generation section. To see this section, be sure your Properties window has the “Categorized” button selected near the top left side, and n...
Page 228 - Performing Queries on Multiple Tables
Chapter 7: Working with Data 205 A data context is the code that is generated by VS when you run the LINQ to SQL item wizard. The Main method instantiates MyShopDataContext, which is the data context. The name came from when the LINQ to SQL item wizard ran and your naming of the *.dbml file. LINQ to...
Page 233 - Inserting Data with LINQ to SQL
210 Microsoft Visual Studio 2010: A Beginner’s Guide VB: Dim myShop As New MyShopDataContext Dim customers As IEnumerable = myShop.GetCustomers() For Each custOrd In customers Console.WriteLine("Name: " & custOrd.Name) Next And here’s the output: Name: Meg Name: Joe Name: May Just call m...
Page 234 - Updating Data with LINQ to SQL
Chapter 7: Working with Data 211 VB: Function InsertCustomer() As Integer Dim cust = New Customer With { .Name = "Jim" } Dim myShop As New MyShopDataContext myShop.Customers.InsertOnSubmit(cust) myShop.SubmitChanges() Return cust.CustomerID End Function As shown here, each collection propert...
Page 235 - Deleting Data with LINQ to SQL
212 Microsoft Visual Studio 2010: A Beginner’s Guide VB: Sub UpdateCustomer(ByVal custID As Integer) Dim myShop As New MyShopDataContext Dim customers = From cust In myShop.Customers Where cust.CustomerID = custID Select cust Dim firstCust As Customer = customers.SingleOrDefault() If (firstCust IsNo...
Page 238 - III
Page 241 - Perform Screen Layout; Starting a WPF Project
218 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Perform Screen Layout ● Use Controls ● Work with Data in the UI W indows Presentation Foundation (WPF) is a .NET technology for building desktop applications. The result of building a WPF application is an *.exe file th...
Page 243 - Understanding Layout; Grid Layout
220 Microsoft Visual Studio 2010: A Beginner’s Guide Similarly, if you add a TextBox element to the XAML, you’ll see the visual representation of that TextBox in Design. You have various controls for manipulating the windows. Both Design and XAML have zoom controls. The zoom tool on Design is a slid...
Page 245 - StackPanel Layout
222 Microsoft Visual Studio 2010: A Beginner’s Guide whatever space remains after the other columns’ sizes are set. After you’ve added content to your Grid, you can use these sizing options to experiment with the layout that you want. One thing to notice in Figure 8-3 is the number in the Grid borde...
Page 246 - Chapter 8: Building Desktop Applications with WPF; DockPanel Layout
Chapter 8: Building Desktop Applications with WPF 223 select the grid, which is added by default to a new project, and delete the Grid. Figure 8-4 shows a StackPanel that contains multiple button controls. In Figure 8-4, it doesn’t matter where you try to lay the buttons—the StackPanel will always l...
Page 247 - WrapPanel Layout
224 Microsoft Visual Studio 2010: A Beginner’s Guide Width properties. Removing the Height and Width properties allows the DockPanel to expand and cover the entire window. Figure 8-5 shows a DockPanel with Label controls in each docking position. Every time you drag and drop a control onto the desig...
Page 248 - Canvas Layout
Chapter 8: Building Desktop Applications with WPF 225 Figure 8-6 demonstrates how you can lay out a group of controls to fill an available space. In the case of the CheckBox controls, the Orientation of the WrapPanel is set to Vertical (the default is Horizontal). When the number of CheckBox control...
Page 249 - Using WPF Controls; Managing Windows for Controls
226 Microsoft Visual Studio 2010: A Beginner’s Guide Now that you know how to use the layout controls, the next section takes a closer look at WPF controls in general, giving you tips on how to use them in your application. Using WPF Controls WPF includes many controls for helping you build user int...
Page 251 - Setting Properties; Handling Events
228 Microsoft Visual Studio 2010: A Beginner’s Guide In Figure 8-8, you can see the Toolbox with the Button control selected. The Designer shows a Button control that has been dragged and dropped. In practice, you’ll be adding this control into some type of layout control so that you can position it...
Page 256 - Coding Event Handlers
Chapter 8: Building Desktop Applications with WPF 233 The previous code shows both the old button1_Click ( Button1_Click in VB) event handler and the new NewOrderButton_Click event handler. You might wonder why the button1_Click event handler wasn’t deleted when you deleted it from the Click event i...
Page 257 - Working with Data in WPF
234 Microsoft Visual Studio 2010: A Beginner’s Guide Notice that the class in this code is named NewOrder , illustrating that a window is just another class. As you know, you can instantiate classes and call their methods, which is the technique you’ll use to open this window from the NewOrder_Click...
Page 258 - Setting Up a Data Source
Chapter 8: Building Desktop Applications with WPF 235 following sections show you how to perform create, read, update, and delete (CRUD) operations via WPF. You’ll first see how to insert data, using VS tools to construct a data entry screen. Then you’ll learn how to read, modify, and delete data th...
Page 264 - Configuring a ComboBox
Chapter 8: Building Desktop Applications with WPF 241 VB: Private Sub Window_Loaded( ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded Dim OrderViewSource As CollectionViewSource = CType(FindResource("OrderViewSource"), CollectionViewSource) Orde...
Page 266 - Reading and Saving Data
Chapter 8: Building Desktop Applications with WPF 243 that was assigned to the Source property of the orderViewSource in Window_Loaded . Coming full circle, the orderViewSource is what the default binding of the containing Grid layout is based on; it was set when dragging and dropping the Order data...
Page 267 - Using the DataGrid
244 Microsoft Visual Studio 2010: A Beginner’s Guide Dim ordList As List(Of Order) ordList = CType(OrderViewSource.Source, List(Of Order)) Dim ord As Order ord = ordList.FirstOrDefault() Dim ctx As New MyShopDataContext ctx.Orders.InsertOnSubmit(ord) ctx.SubmitChanges() MessageBox.Show("Order Sa...
Page 273 - Learn What MVC Means; Understanding ASP.NET MVC
250 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Learn What MVC Means ● Create Models ● Create Controllers ● Create Views ● Work with Data in ASP.NET MVC A SP.NET is a .NET technology for building Web applications. VS provides support for building a Web application th...
Page 274 - Chapter 9: Creating Web Applications with ASP.NET MVC; Starting an ASP.NET MVC Project
Chapter 9: Creating Web Applications with ASP.NET MVC 251 View, and the Controller, including relationships. There are variations of the relationship between Model, View, and Controller, so rather than a theoretically correct depiction of all scenarios, Figure 9-1 is a simplification that should hel...
Page 277 - Creating the Models
254 Microsoft Visual Studio 2010: A Beginner’s Guide The skeleton code produced by VS gives you some working examples that you can build on and move forward. One item that VS doesn’t produce is the Model, which is discussed next. Creating the Models As stated previously, the Model represents the dat...
Page 279 - Displaying Views; Looking Inside a View
256 Microsoft Visual Studio 2010: A Beginner’s Guide TIP You can change your VS Web server’s port number. If you open your project’s property page by right-mouse clicking on the project in Solution Explorer and select Properties, then select the Web tab on the left, under Servers, you can specify a ...
Page 281 - Organizing View Files; Assigning MasterPage Files
258 Microsoft Visual Studio 2010: A Beginner’s Guide Organizing View Files The file structure in Figure 9-2 shows that Views appear in the Views folder and have a *.aspx file extension. Each subfolder under the Views folder corresponds to a Controller, and the Views within the subfolder correspond g...
Page 285 - Managing Routing
262 Microsoft Visual Studio 2010: A Beginner’s Guide Managing Routing ASP.NET MVC has a routing system that matches URLs to controllers with actions and the parameters passed to those actions. When you start a new ASP.NET MVC project, default routing will be established via a file called Global.asax...
Page 287 - Building a Customer Management Application
264 Microsoft Visual Studio 2010: A Beginner’s Guide Listing 9-5 shows that the Application_Start event invokes a method named RegisterRoutes, passing the Routes property of the RouteTable class. The Routes property is a static RouteCollection, meaning that there is only one copy for the entire appl...
Page 288 - Creating a Repository
Chapter 9: Creating Web Applications with ASP.NET MVC 265 Creating a Repository A common pattern for working with data is to build a repository that is responsible for all data-related operations. This is another way to promote separation of concerns so that you isolate logic into specific parts of ...
Page 291 - Creating a Customer Controller
268 Microsoft Visual Studio 2010: A Beginner’s Guide (From cust In m_ctx.Customers Select cust).ToList() Return customers End Function Public Sub DeleteCustomer(ByVal custID As Integer) Dim customer = (From cust In m_ctx.Customers Where cust.CustomerID = custID Select cust).SingleOrDefault() m_ctx.C...
Page 292 - Displaying a Customer List
Chapter 9: Creating Web Applications with ASP.NET MVC 269 This will create a new Controller with several methods for working with Customer data. Listing 9-1 already showed what a Controller looks like, and this is no different, except that it contains more action methods. The following sections expl...
Page 297 - Adding a New Customer
274 Microsoft Visual Studio 2010: A Beginner’s Guide As shown in Figure 9-6, the Customer tab appears first on the list, and clicking it shows the list of Customers. In addition to the content you see in the list, there are links, such as Edit and Create. The next section covers the Create operation...
Page 302 - Updating Existing Customers
Chapter 9: Creating Web Applications with ASP.NET MVC 279 Updating Existing Customers Similar to how we created Customers, you also need two methods for editing a Customer. The get method populates an edit form with existing data, and the post method saves the changes. Listing 9-11 shows these two m...
Page 304 - Deleting a Customer
Chapter 9: Creating Web Applications with ASP.NET MVC 281 Return RedirectToAction("Index") Catch Return View() End Try End Function In the get Edit action method, you need to get a reference to the current record, indicated by the id being passed in, and pass that reference to the View for d...
Page 309 - Start a New Silverlight Project; Starting a Silverlight Project
286 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Start a New Silverlight Project ● Work with the Silverlight Designer ● Add Controls to an Application ● Play Silverlight Videos ● Deploy Silverlight Applications S ilverlight is a Web technology that allows you to add a...
Page 310 - Chapter 10: Designing Silverlight Applications
Chapter 10: Designing Silverlight Applications 287 Figure 10-1 Creating a new Silverlight application Figure 10-2 A new Silverlight project
Page 313 - Navigating the Silverlight Designer
290 Microsoft Visual Studio 2010: A Beginner’s Guide Navigating the Silverlight Designer The underlying technology for displaying the UI is XML Application Markup Language (XAML), pronounced “Zamel.” Appendix A contains an introduction to XML, and Appendix B contains an introduction to XAML if you n...
Page 320 - Deploying Silverlight Applications
Chapter 10: Designing Silverlight Applications 297 Deploying Silverlight Applications You can deploy a Silverlight application to a Web site, as you would an ASP.NET MVC application. However, you’ll need to ensure the MIME type and policy is in place to ensure the application will run outside of you...
Page 323 - Create a Web Service
300 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Create a Web Service ● Deploy a Web Service ● Write a Client That Consumes the Web Service W indows Communication Foundation (WCF) is a .NET technology for creating Web services. A Web service is software that provides ...
Page 324 - Chapter 11: Deploying Web Services with WCF; Starting a WCF Project
Chapter 11: Deploying Web Services with WCF 301 call into XML and send the XML data via HTTP to the WCF service. The WCF service understands the XML because it was the WCF service that told the Java application what format to put the XML into. If you’re curious about the format, it’s called Web Serv...
Page 325 - Specifying a Contract with WCF Interfaces; Examining the VS-Generated Contract
302 Microsoft Visual Studio 2010: A Beginner’s Guide The WCF Service Library starts with two files with default names of IService1.cs (IService1.vb for VB) and Service1.cs (Service1.vb for VB), which contain an interface and a class that implements that interface. If you need to brush up on interfac...
Page 328 - Creating Your Own Contract
Chapter 11: Deploying Web Services with WCF 305 The GetDataUsingDataContract method illustrates a method that uses a custom type, CompositeType, as a parameter and return type. Being a custom type, CompositeType has attributes that help define its contract: DataContract and DataMember. The DataContr...
Page 331 - Implementing Logic with WCF Classes
308 Microsoft Visual Studio 2010: A Beginner’s Guide Using a custom type for the purpose of lookup controls at the UI level, such as the CustomerLookup class in Listing 11-3, opens the potential to only communicate information that is necessary, rather than an entire object where all of the data isn...
Page 337 - Hosting a WCF Service
314 Microsoft Visual Studio 2010: A Beginner’s Guide Where cst.CustomerID = custID Select cst).SingleOrDefault() If Not (customer Is Nothing) Then ctx.Customers.DeleteOnSubmit(customer) ctx.SubmitChanges() End If End Sub End Class The implementation of CustomerService is similar to what you’ve seen ...
Page 338 - Following General Hosting Procedures
Chapter 11: Deploying Web Services with WCF 315 Following General Hosting Procedures For better security, IIS doesn’t install with the default installation of the Windows OS. There are different versions of Windows for desktop and server, so I’ll provide a general description of what you need to do ...
Page 340 - Creating a Web Site on IIS 7 on Windows 7; Order of Installations Matter
Chapter 11: Deploying Web Services with WCF 317 3. This example enables FTP, which is one of the ways you can deploy a Web site. Ensure the option for “Ensure IIS Metabase and IIS 6 configuration compatibility,” under the IIS 6 Management Compatibility branch, is selected. When you click OK, the IIS...
Page 344 - Deploying the WCF Service to IIS
Chapter 11: Deploying Web Services with WCF 321 Deploying the WCF Service to IIS If you want to run the WCF service in VS, you don’t have to do anything because VS already set the project up to run with a built-in server. The discussion in this section is intended to help you deploy to IIS on a Wind...
Page 349 - Communicating with a WCF Service; Creating a Service Reference
326 Microsoft Visual Studio 2010: A Beginner’s Guide Normally, you don’t want to deploy the App_Data folder because it might hold a database file that is huge and would slow down your application considerably. Of course, if you have SQL Server Express installed at the deployment location and need th...
Page 352 - Coding Web Service Calls
Chapter 11: Deploying Web Services with WCF 329 Now that you have a service reference, you can use it in any .NET application. The following section shows you how to write code to communicate with the Web service. Coding Web Service Calls This section will explain how to write code that communicates...
Page 359 - Deploying a Client That Consumes a Web Service
336 Microsoft Visual Studio 2010: A Beginner’s Guide newCustID = svc.InsertCustomer(newCust) Console.WriteLine("New Customer ID: " & newCustID) Dim cust As New Customer cust = svc.GetCustomer(newCustID) cust.Income = 49000 svc.UpdateCustomer(cust) Dim updatedCust As Customer updatedCust ...
Page 360 - Creating a Web Service in a Web Site
Chapter 11: Deploying Web Services with WCF 337 Regardless of the name, each configuration file will have a system.serviceModel element with configuration settings for the Web service. Listing 11-8 shows parts of the configuration file that you should find to change the address of the Web service to...
Page 362 - IV
Page 365 - Implement Custom Templates; Implementing Custom Templates
342 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Implement Custom Templates ● Create Custom Snippets ● Write Macros I n addition to all the great features you’ve seen in preceding chapters, VS gives you the capabilities to customize your own environment. The customiza...
Page 366 - Chapter 12: Customizing the Development Environment; Creating New Project Templates; Modifying a Project
Chapter 12: Customizing the Development Environment 343 Creating New Project Templates If you’re working on a single project that lasts a long time, you might be satisfied with using a default template and doing a one-time modification. However, if you are starting new projects on a regular basis, c...
Page 367 - Exporting the Project Template
344 Microsoft Visual Studio 2010: A Beginner’s Guide 7. To make sure your changes are okay, build and run the project. Select Build | Rebuild Solution and ensure you don’t receive compiler errors. Then press F 5 to run and allow VS to modify the Web.config file. Since you’ve commented out the route ...
Page 369 - Using the New Project Template
346 Microsoft Visual Studio 2010: A Beginner’s Guide You can share the project template with other developers too. The next section shows what to do to get the project template to appear in VS. Using the New Project Template The instructions for exporting the project template in the preceding sectio...
Page 370 - Creating New Item Templates; Creating an Item Template
Chapter 12: Customizing the Development Environment 347 Prompt (2010) and select Run As Administrator. This will take a few minutes to run, but afterward you’ll see the project appear in the VS New Project window. This command imports all of the project templates from the global project templates fo...
Page 371 - Exporting the Item Template
348 Microsoft Visual Studio 2010: A Beginner’s Guide 3. Add the following code to the file: C#: /// <summary> /// Enum description /// </summary> public enum MyEnum { /// <summary> /// Item 1 description /// </summary> Item1, /// <summary> /// Item 2 description /// <...
Page 374 - Using an Item Template
Chapter 12: Customizing the Development Environment 351 After you click Finish, VS does two things: it saves to the output location and makes the template available in VS. The output location is just a place to store the item template, Enum.zip, which contains all of the information VS needs to disp...
Page 376 - Creating Custom Snippets; Creating a New Snippet
Chapter 12: Customizing the Development Environment 353 including CSharp VisualBasic, Web, and more, each folder corresponding to folders in the VS New Item window. Under each folder is a locale code—for instance, English is 1033—and you would copy the file into the locale folder for the category yo...
Page 377 - Examining Existing Snippets
354 Microsoft Visual Studio 2010: A Beginner’s Guide Examining Existing Snippets Snippets that ship with VS are located at \Program Files\Microsoft Visual Studio 10.0 under a folder for the language (VC#, VB, XML, and more) you need to find a snippet for. There, you’ll either find one or more folder...
Page 379 - Creating New Snippets
356 Microsoft Visual Studio 2010: A Beginner’s Guide fill in data items when filling in the snippet template in VS. The $end$ variable defines where the cursor ends up after the snippet is complete (after pressing ENTER in the snippet template). You’ll want to locate $end$ where a developer would no...
Page 381 - Managing the Snippet Library; File Folders Holding Snippets
358 Microsoft Visual Studio 2010: A Beginner’s Guide <Literal> <ID>return</ID> <Default>void</Default> <ToolTip>Return value</ToolTip> </Literal> <Literal> <ID>methodName</ID> <Default>MethodName</Default> <ToolTip>N...
Page 382 - Using the Snippets Manager
Chapter 12: Customizing the Development Environment 359 10.0\. You’ll see language technology folders, such as VC# for C# or VB for VB. Within those folders, you’ll either see folders for language codes (English is 1033) or a Snippets folder. Drilling down two levels, through the language code folde...
Page 383 - Writing Macros; Recording a Macro
360 Microsoft Visual Studio 2010: A Beginner’s Guide Writing Macros When the productivity features that ship with VS and custom snippets don’t give you enough power, the next step is to consider creating a macro, which is a repeatable set of actions that you can record and re-run multiple times. An ...
Page 387 - Saving a Macro
364 Microsoft Visual Studio 2010: A Beginner’s Guide In the preceding code, I’ve moved the ArgumentNullException arguments to separate lines to fit the book’s line length, but this is what you should see. Next, you can test the macro by running it. Click the lastName parameter and select Tools | Mac...
Page 388 - Editing Macros
Chapter 12: Customizing the Development Environment 365 In the Macro Explorer, you can add new Macro Projects, which are containers for holding macro modules, by right-clicking Macros and selecting New Macro Project. If someone shares their Macro Project with you, right-click Macros and select Load ...
Page 395 - Create an Add-In with VS; Creating a Visual Studio Add-In; Running the Add-In Project Wizard
372 Microsoft Visual Studio 2010: A Beginner’s Guide Key Skills & Concepts ● Create an Add-In with VS ● Learn What Types of Add-Ins to Create ● Deploy an Add-In P revious chapters discussed many ways to use VS, and the preceding chapter showed you a few ways to create your own customizations. In...
Page 396 - Chapter 13: Extending Visual Studio 2010
Chapter 13: Extending Visual Studio 2010 373 1. Open VS and press CTRL - SHIFT - N to open the New Project window. Select Other Project Types | Extensibility and observe that there are two types of Add-In project types: Visual Studio Add-In and Shared Add-In. The Shared Add-In is what you would use ...
Page 400 - Examining an Add-In Wizard Solution
Chapter 13: Extending Visual Studio 2010 377 Examining an Add-In Wizard Solution After running the New Project Add-In Project Wizard, you’ll have a solution with a project that has skeleton code forming the basis of the application. Not only will you need to know what files are available, but you’ll...
Page 401 - Drilling into the
378 Microsoft Visual Studio 2010: A Beginner’s Guide methods that are numbered, such as the IDTExtensibility and IDTExtensibility2, where IDTExtensibility2 is a more recent version with additional members. I’ll explain what the IDTExtensibility2 interface does later, but what you should get out of t...
Page 406 - Adding Functionality to an Add-In
Chapter 13: Extending Visual Studio 2010 383 /// <summary> /// Implements the Exec method of the IDTCommandTarget /// interface. This is called when the command is invoked. /// </summary> /// <param term='commandName'> /// The name of the command to execute. /// </param> /// ...
Page 407 - Reviewing the; Understanding
384 Microsoft Visual Studio 2010: A Beginner’s Guide Reviewing the OnConnection Method As you learned earlier, the Connect class implements various interface methods so that VS can call into those methods to run your Add-In. One of the primary methods is OnConnection, which is a member of the IDTExt...
Page 408 - Reviewing
Chapter 13: Extending Visual Studio 2010 385 Reviewing OnConnection Generated Code You know that the purpose of the OnConnection method is to help initialize the Add-In, and you’ve seen the parameters populated by VS and what each parameter means. Listing 13-2 shows the code generated by VS after th...
Page 414 - Implementing the
Chapter 13: Extending Visual Studio 2010 391 As you may recall, the OnConnection method assigned the main application object to _applicationObject, a field of the Connect class. This is important because now you have access to the main application object, and you’ll see how it’s used in the next sec...
Page 418 - Setting Status with
Chapter 13: Extending Visual Studio 2010 395 ", Shortcut: " + bindingStr + "\n"); } } handled = true; VB: For Each cmd As Command In _applicationObject.Commands Dim cmdBindings As Object() = CType(cmd.Bindings, Object()) If cmdBindings.Length > 0 Then Dim bindingStr As String = St...
Page 422 - Where to Go Next
Chapter 13: Extending Visual Studio 2010 399 Once the Add-In is deployed and loaded, a user can run the Add-In by selecting Tools | KeystrokeFinder. When the Add-In runs, the Output window will contain a listing of commands and shortcut keys. To see the results, you should open the Output window, CT...
Page 426 - Appendix; Introduction to XML
Page 427 - XML Prefixes
404 Microsoft Visual Studio 2010: A Beginner’s Guide E xtensible Markup Language (XML) is an open-standards cross-platform way of specifying documents. At its origins, XML was used to represent data, but it has grown in use to include user interface technologies and even executable logic. While ther...
Page 428 - Appendix A: Introduction to XML; XML Elements; Attributes
Appendix A: Introduction to XML 405 The prefix is common for letting applications reading the document know that it is indeed an XML document. The version is self-describing. Encoding is important because it specifies the binary format of the text. If you have one application passing data to another...
Page 429 - Namespaces
406 Microsoft Visual Studio 2010: A Beginner’s Guide Namespaces Another important part of XML that you’ll need to understand is namespaces. In Chapter 2, you learned how namespaces in C# and VB help give a unique identity to code within a given namespace. The purpose of namespaces in XML is similar....
Page 430 - The XML Menu; Configuring XML Options
Appendix A: Introduction to XML 407 addresses namespace. The convenience of prefixes is that they help the XML be more readable. In Listing A-2, the address namespace is decorated with the a: prefix, as in <a:address> to indicate that address belongs to the http://somedomain.com/addresses name...
Page 432 - Introduction to XAML
Page 434 - Appendix B: Introduction to XAML; Elements as Classes
Appendix B: Introduction to XAML 411 is that it is an XML document with elements, attributes, and namespaces. Each of the items you see has special meaning, as will be discussed in the following sections. Elements as Classes For XAML to be meaningful as code, elements must be associated with classes...
Page 435 - Property Elements
412 Microsoft Visual Studio 2010: A Beginner’s Guide Property Elements You’ve seen how attributes translate to properties. In addition to attributes, XAML has property elements, which are child elements where one or more other elements become assigned to a property. An example of a property element ...
Page 437 - Markup Extensions
414 Microsoft Visual Studio 2010: A Beginner’s Guide TIP VS provides XAML editor support by allowing you to place your cursor between begin and end tags, pressing ENTER , and indenting the start position of the cursor on the new line between the start and end tags. From that point, you can type <...
Page 440 - Symbols
417 Index Symbols < > (angle brackets), 405 { } (braces), 40, 57, 160 ? (question mark), 162 _ (underline), 55 / integer, 62 & operator, 62 + operator, 62 A accessors, 84, 86 Add Reference window, 122–123 Add-In Project Wizard, 372–383, 398 add-ins, 371–400 adding functionality to, 383–397...