Book Image

Microsoft SharePoint 2010 Development with Visual Studio 2010 Expert Cookbook

By : Balaji Kithiganahalli
Book Image

Microsoft SharePoint 2010 Development with Visual Studio 2010 Expert Cookbook

By: Balaji Kithiganahalli

Overview of this book

Microsoft SharePoint 2010, is the best-in-class platform for content management and collaboration. With the combined capabilities of Sharepoint and Visual Studio, developers have an end-to-end business solutions development IDE. To leverage this powerful combination of tools it is necessary to understand the different building blocks. This book will provide necessary concepts and present ways to develop complex business solutions and take them further.SharePoint 2010 Development Cookbook With Visual Studio 2010 is an instructional guide for developing and debugging applications for SharePoint 2010 environment using Visual Studio 2010. The cookbook approach helps you to dip into any recipe that interests you, you can also read it from cover to cover if you want to get hands on with the complete application development cycle.With this book you will learn to develop event handlers, workflows, content types, web parts, client object model applications, and web services for SharePoint 2010 in an instructional manner. You will discover the less known facts behind debugging feature receivers, deployment of web parts, utilizing free toolkits to enhance the development and debugging experience. You will learn the newer development approach called Visual Web Parts, how to develop and deploy Silverlight applications that can be used with Silverlight web part. You will also explore SandBoxed deployment model and its usage. You will create your own web services for SharePoint and the Client Object Model introduced in SharePoint 2010. All in all, you will develop Sharepoint solutions in an instructional manner that eases the learning process.
Table of Contents (15 chapters)
Microsoft SharePoint 2010 Development with Visual Studio 2010: Expert Cookbook
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Deploying Event Receivers


During the previous recipes, we saw Visual Studio automatically uploading a solution and activating it for our test purposes. The entire step-by-step process that Visual Studio does in order to deploy a solution to the site can be seen in the output window as shownin the following screenshot Development is all done and now we need to deploy this solution to production. Here are the step-by-step instructions on how we deploy solutions:

Getting ready

It is necessary to understand the concept of event receivers to follow through this recipe. It is advised to complete the previous recipes sucessfully.

How to do it...

  1. If you have closed Visual Studio IDE, launch it as an administrator.

  2. Open the previously created ListItemEventReceiver solution.

  3. Open the project properties window by right-clicking the project and selecting Properties.

  4. Select the Build Tab and set the Configuration to Active (release).

  5. Rebuild the solution from menu Build | Rebuild.

  6. From the same build menu, select Package to make a package of this solution. This will generate a .wsp solution file in the bin folder of your solution as shown:

  7. You can use the stsadm command to deploy this solution file to any site in the farm.

  8. To add the solution to the solution store use the command:

      stsadm –o addsolution –filename ListItemEventReceiver.wsp
    
  9. To deploy the solution use the command:

      stsadm –o deploysolution –name ListItemEventReceiver.wsp –local -allowgacdeployment
    
  10. Now install the feature by using the command:

    stsadm –o installfeature –filename ListEventReceiver_Feature1\Feature.xml
    
  11. You can navigate to Manage Site Features from Site Action | Site Actions | Manage Site Features. You should see your Feature deployed to the site but not activated as shown:

  12. You can activate the feature by clicking the Activate button.

How it works...

When we built and packaged our solution, a .wsp solution file was created. This is nothing but a CAB file contaning feature file and the items that the feature is going to install. You can rename the .wsp file to a .CAB extension and open it through any ZIP file extractor. The following is a screenshot showing the contents of a .wsp file:

The .wsp file contains the DLL, Application Page, and three different XML documents. These XML documents provide the necessary information on where the resources need to be deployed. Open up the manifest.xml in notepad. You can see it lists the locations of the Application Page, Event Receiver DLL, and the Feature.

In SharePoint, a Feature is nothing but an XML file. The XML file is named Feature.xml. This XML contains the name, the ID, and the scope information of the feature. The name and the ID attributes of the Feature uniquely identifies the Feature. An ID is a GUID in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" where x is a hexadecimal number that can be from 0-9 and a-f. When you created the solution, Visual Studio automatically created this GUID. Feature.xml also includes the location of the Event Receiver's Elements.xml.

Scope indicates how the Feature needs to be scoped. You can scope a Feature in four ways:

  1. Farm Level: This can be activated at a farm level. That is, all the web applications in the farm will have access to the feature.

  2. Site Level: Can be activated at site collection level, meaning all the sites in the sites collection will have access to this feature.

  3. Web Level: Can be activated for a specific website.

  4. Web Application Level: Can be activated for all sites in the web application.

We already went through the Elements.xml in the previous recipe and it basically contains the information about the Event Receiver that we deployed.

There's more...

You can use PowerShell commands to install and activate features instead of stsadm commands. The corresponding PowerShell commands for the STSADM commands that we have used in this recipe are:

Add-SPSolution –LiteralPath <Location of your wsp>
Install-SPSolution -Identity <WSPName> -WebApplication <URLname>
Enable-SPFeature FeatureFolderName -Url <URLName>

See also

  • Creating a Feature Receiver recipe