Getting Started with SharePoint 2010 Developer Tools in Visual Studio 2010

SharePoint Visual How To

Summary:  Learn how to create, test, and debug Microsoft SharePoint 2010 projects using the new SharePoint development tools in Microsoft Visual Studio 2010.

Applies to: Office 2010 | SharePoint Foundation 2010 | SharePoint Server 2010 | Visual Studio | Visual Studio 2008 | Visual Studio 2010

Provided by:  Ted Pattison, Critical Path Training, LLC (SharePoint MVP)

Overview

The SharePoint development tools in Microsoft Visual Studio 2010 provide you with new levels of support and productivity. This Microsoft SharePoint 2010 Visual How To guides you through the process of creating your first SharePoint project.

Code It

Start by creating a local SharePoint site by using the Blank site template. You will use this site as a test site. The point of using a Blank site is that it has a simple Web Parts page as its home page.

In Microsoft Visual Studio 2010, create a new SharePoint 2010 project named WingtipDevProject1, using the Empty SharePoint Project template. When you are prompted by the SharePoint Configuration Wizard, add the URL of the local test site, and then click Deploy as farm solution. Now, build the project by using the following steps.

To build the SharePoint project

  1. In Solution Explorer, right-click the WingtipDevProject1 project node, click Add, and then click New Item. In the Add New Item dialog box, create a new Web Part project item named HelloPart.

  2. Locate the new feature node for Feature1, and double-click it to display it in the Feature Designer. Change the Title of the feature to Wingtip Dev Project 1. Close the Feature Designer.

  3. Verify that there are three source files inside the HelloPart project item named elements.xml, HelloPart.cs, and HelloPart.webpart.

  4. Open the Web Part Description file named HelloPart.webpart. Change the Title to The Hello Part, and change the Description to My Description. Close HelloPart.webpart.

  5. Open the element manifest file named elements.xml. Locate the Property element with the property named Group. Change the Value of the Group property from Custom to Wingtip Web Parts. Close elements.xml.

  6. In the Web Part source file named HelloPart.cs, implement the Web Part by using the following code.

    namespace WingtipDevProject1.HelloPart {
      [ToolboxItemAttribute(false)]
      public class HelloPart : WebPart {
    
        protected Label lbl;
    
        protected override void CreateChildControls() {
          lbl = new Label();
          lbl.Text = "Hi from the Hello Part";
          this.Controls.Add(lbl);
        }
      }
    }

Now that you have implemented a simple SharePoint project with a Web Part, it's time to test your work.

To test the SharePoint project and Web Part

  1. Ensure that the Visual Studio 2010 Output Window is visible. If you cannot see the Output Window, on the Visual Studio 2010 View menu, click Output. Or, use the keyboard shortcut CTRL+ALT+O.

  2. In Solution Explorer, right-click the WingtipDevProject1 project node and execute the Deploy command. Watch the progress of the Deploy command in the Output Window.

  3. After the Deploy command completes, return to the test site in the browser and refresh the home page. On the Site Actions menu, click Edit Page to view the current Web Parts page in design mode.

  4. Click the Add a Web Part link in the Left zone to add a Web Part to the page. Select the The Hello Part in the Wingtip Web Parts category, and then add it to the Left zone of the current page. Change the current Web Parts page from design view back to display view to see your Web Part.

  5. Close the browser and return to Visual Studio 2010. Open the source file HelloPart.cs and add a break point to the first line of code inside the CreateChildControls method. Now, press the F5 key to enter debug mode. Wait until the debugger hits your break point. Then, step through your code line by line.

Read It

The SharePoint development tools in Visual Studio 2010 provide a much improved development experience for building business solutions in SharePoint 2010.

The SharePoint development tools in Visual Studio 2010:

  • Provide an end-to-end developer experience for SharePoint 2010.

  • Extend the Visual Studio project system to create a special kind of project known as a SharePoint project.

  • Provide project templates in Visual Studio 2010 for creating SharePoint projects.

  • Provide project item templates for SharePoint projects that are used to create SharePoint project items.

  • Make the process of building the CAB file for the solution package transparent to the developer.

  • Are extensible by third-party developers.

See It

Watch the video

> [!VIDEO https://www.microsoft.com/en-us/videoplayer/embed/ed5de51f-61a3-4e7b-b289-d8dc0104dff3]

Length: 00:10:56

Explore It

About the Author

MVP Contributor Ted Pattison is an author, instructor, and co-founder of Critical Path Training, a company dedicated to education on SharePoint technologies. As a Microsoft SharePoint Most Valuable Professional (MVP), Ted frequently works with the Microsoft Developer Platform Evangelism group to research and author SharePoint training material for developers early in the product life cycle while in its alpha and beta stages. Ted is also co-author of Inside Microsoft SharePoint 2010.