Share via


Exercise 1: Creating a SharePoint 2010 Project

In the first exercise, you will create an empty project and focus on the aspects of the Visual Studio 2010 SharePoint Tools that are common across all projects created with this toolset. Most of your work will involve changing the properties of the project and properties of the project's main feature.

  1. If you haven’t already done so, run the batch file named SetupLab02.bat, found in the c:\Student\Labs\02_VS2010_SPT\ folder, to create the new site collection that will be used to test and debug the code you will be writing in this lab. This batch file creates a new site collection at an URL of https://intranet.contoso.com/sites/Lab02.
  2. Launch the Internet Explorer and navigate to the top-level site at https://intranet.contoso.com/sites/Lab02. You should observe that the newly-created site is a Blank site. This is the site you will use to test and debug the project you will develop throughout this entire lab exercise.

    Figure 1

    Blank site

  3. Now launch Microsoft Visual Studio 2010 with administrator privileges by right-clicking on its Start menu shortcut and clicking the Run as Administrator option. Starting Visual Studio in this manner (i.e. with administrative permissions) makes Visual Studio debugger work correctly when attaching to the SharePoint worker process.

    Figure 2

    Launch Visual Studio 2010

  4. Create a new Visual Studio project named ContosoWebParts based on the SharePoint Tools project of type Empty Project. You can find this project type using the path Visual C#/Visual Basic » SharePoint » 2010. Ensure the .NET Framework 3.5 is selected instead of the default .NET Framework 4.0. Also, remove the check from the Create directory for solution checkbox. Failure to do so will result in a namespace of ContosoWebParts.ContosoWebParts being generated (instead of ContosoWebParts) which may cause issues later in this lab.

    Figure 3

    Create an empty SharePoint project

  5. Click OK to start the SharePoint Customization Wizard.
  6. When the SharePoint Customization Wizard prompts you for a local debugging site, enter the URL of https://intranet.contoso.com/sites/Lab02. Change the trust level to Deploy as a farm solution and then click Finish.

    Figure 4

    The SharePoint Customization Wizard

    In the Solution Configurations drop-down box, located near the center of the toolbar, select Configuration Manager…

    Figure 5

    The target platform must be set to x64 or Any CPU

  7. On the Configuration Manager dialog box, in the Active solution platform drop-down box note that for SharePoint Project types the default platform is Any CPU. Close the Configuration Manager window.
  8. Once the new project has been created, you should be able to observe it has several nodes, two of which are Features and Package. The Features node and the Package node are unique to projects created with the Visual Studio 2010 SharePoint Tools.

    Figure 6

    The Solution Explorer C#/VB.NET

  9. Right-click the Features node and choose Add Feature. A feature with the name Feature1 is added. Right-click on this node and click Rename. Rename this feature to Main.

    Figure 7

    Add a new feature to the project. C# shown/VB.NET Similar in Features area

  10. Double-click the Main feature to open the feature in the feature designer. Use the feature designer to change the feature’s Title and Description using the following values:
    1. Title: Custom Web Parts
    2. Description: My very first project using the Visual Studio 2010 Tools
  11. You must also change the Scope setting of the Main feature from the default value of Web to a value of Site.

    Note:
    Don't be confused here. Remember a Scope setting of Web results in site-level activation of the feature while a Scope setting of Site results in activation at the site collection level. The change of the feature's Scope setting to Site is required due to the fact that Web Parts deployment requires a feature which activates at site collection scope in order to properly deploy Web Part description files.

    Figure 8

    The Feature Designer. C# shown, VB.NET similar in Main.Feature properties area

  12. Now you are going to add a few graphic images into your project so they are deployed inside the SharePoint Images folder. The first step to doing this correctly is to add a mapped folder to your project for the SharePoint Images folder. Accomplish this by right-clicking the ContosoWebParts project in the Solution Explorer, expanding the Add menu and selecting the SharePoint "Images" Mapped Folder command.

    Figure 9

    Add the SharePoint Images mapped folder. C# shown, VB.NET similar.

  13. After completing the previous step you should be able to see that there is an Images directory inside your project. You should also be able to observe that there is a child folder inside the Images folder with the same name as the project ContosoWebParts.
    Note:
    This demonstrates how the SPT helps to ensure best practices with SharePoint development. When adding image files to your project, do not add them directly inside the Images folder. Instead, add them to the inner directory in this case named ContosoWebParts to avoid file name conflicts with the image files that Microsoft deploys inside the Images directory.
  14. There are three GIF files inside the folder C:\Student\Labs\02_VS2010_SPT\StarterFiles. These files are named FeatureIcon.gif and SiteIcon.gif, WebPartIcon.gif. Right-click on the ContosoWebParts folder inside the Images folder and select the Add » Existing Items... command. When the resulting dialog opens, navigate to the folder location that contains the GIF files. Add all three GIF files to the project.

    Figure 10

    Add a number of images to the Images mapped folder. C# shown, VB.NET similar Images folder.

  15. The first GIF file that you will put to use is the FeatureIcon.gif by modifying the ImageUrl property of the Main feature.

    a.Open the Main feature in the feature designer and make sure it is the active window. (Note: if necessary, double click on the Main feature in the Solution Explorer to open the designer. Now click in the Main.Feature window to activate it).

    b.Find the property sheet for the Main feature (on the lower right side of the screen)

    c.Update the Image Url property with an URL that is relative to the Images which should be ContosoWebParts\FeatureIcon.gif.

    Figure 11

    Change the Image Url property of the feature

  16. Save all the work you have done to the Main feature.
Note:
In this exercise you created your first feature using the SPT tools and added a mapped folder to the project. In future exercises you’ll add additional pieces to the project to make it more useful.