Monday 1 December 2014

Event Receivers in SharePoint: A complete guide


1. Introduction

While developing any application we need to handle some events. For example, when a new item is added to a list, we may need to perform some action like say, notifying the person who created the list item, or modifying the dependent entries in some other location etc. Handling of such events is facilitated by event receivers. We have many SharePoint event receiver classes in order to handle variety of events.



2. SharePoint Event Receiver types

There are basically two types of event receivers: Synchronous and Asynchronous event receivers.Synchronous event receivers are also known as ‘Before’ event receivers. They are used to perform some custom action before an event occurs. In this case, there is a flexibility of cancelling the event on some conditions so that the event that gets initiated will not occur.
Asynchronous event receivers are also known as ‘After’ event receivers. They are used to perform some custom action after an event occurs. These events are asynchronous because they need not happen immediately after the event is performed. They can happen sometime later also, unlike synchronous event receivers which occur immediately before an event occurs.

3. Classes of Event Receivers

There are fundamentally five classes for Event Receivers for SharePoint 2007.
Microsoft.SharePoint.SPEmailEventReceiver : This provides event handling whenever a  user sends an email to a list on which e-mail feature is enabled
Microsoft.SharePoint.SPFeatureReceiver :  This provides event handling whenever is feature is acted upon
Microsoft.SharePoint.SPItemEventReceiver : This provides event handling whenever any action is performed on a list item
Microsoft.SharePoint.SPListEventReceiver : This provides event handling whenever a list definition is modified like adding or deleting columns and modifying existing columns.
Microsoft.SharePoint.SPWebEventReceiver : This provides event handling whenever a site or a site collection is deleted or moved
Each of the classes has some virtual methods which are to be over-ridden to perform our custom action. Those methods are as follows.



3.1 Site Level Events

Methods under the class SPWebEventReceiver handle site level events. A brief overview of those methods is as follows.
Site Deleted – This occurs after a site collection is deleted.
Site Deleting – This occurs before a site collection is being deleted.
Web Deleted – This occurs after a website has been deleted completely. This is an asynchronous after event.
Web Deleting – This occurs before a website is deleted. This is a synchronous before event.
Web Moved – This occurs after an existing website is moved. This is an asynchronous after event.
Web Moving – This occurs before a website is moved. This is a synchronous event.

3.2 List Level Events

Methods under the class SPListEventReceiver handle list level events. A brief overview of those methods is as follows.
Field Added – This occurs after a field link is added to a list.
Field Adding – This occurs when is field is being added to a content type.
Field Deleted – This occurs after a field is deleted from a list.
Field Deleting – This occurs when a field is being deleted from a list.
Field Updated – This occurs after a field is updated in a list.
Field Updating – This occurs when a field is being updated in a list.

3.3 Item Level Events

Methods under the class SPItemEventReceiver handle item level events. A brief overview of those methods is as follows.
ItemAdded – This occurs after a new item is added to a list. This is an asynchronous after event.
ItemAdding – This occurs before an item is added to a list. This is a synchronous before event.
ItemAttachmentAdded – This occurs after an attachment is added to a list. This is an asynchronous event.
ItemAttachmentAdding – This occurs while an attachment is being added to a list.
ItemAttachmentDeleted – This occurs after an attachment is removed from an item.
ItemAttachmentDeleting – This occurs while an attachment is being removed from an item.
ItemCheckedIn – This occurs after an item is checked in.
ItemCheckedOut – This occurs after an item is checked out.
ItemCheckingIn – This occurs while an item is being checked in.
ItemCheckingOut – This occurs while an item is being checked out.
ItemDeleted – This occurs after an item is deleted from its list.
ItemDeleting – This occurs while an item is being deleted from its list.
ItemFileConverted – This occurs when the type of file is being converted.
ItemFileMoved – This occurs after a file is moved.
ItemFileMoving – This occurs while a file is being moved.
ItemUncheckedOut – This occurs after un-checking an item in a list.
ItemUncheckingOut – This occurs while an item is being unchecked.
ItemUpdated – This occurs after an item is updated.
ItemUpdating – This occurs while an item is being updated.

3.4 Feature Events

Methods under the class SPFeatureReceiver handle events related to feature. A brief overview of those methods is as follows.
FeatureActivated – This occurs after a feature is activated.
FeatureDeactivating – This occurs when a feature is being deactivated.
FeatureInstalled – This occurs after a feature is installed.
FeatureUninstalling – This occurs when a feature is being uninstalled.

3.5 Email Events

Method under the class SPEmailEmailEventReceiver handles the event related to email. A brief overview of the method is as follows.
EmailReceived This occurs after an email message has arrived (to an email enabled list).

4. Binding the Event Receivers

For the event receivers to receive an event, they should be bound to the corresponding objects. This binding can be done in three ways.
Using a feature
Using a content type
Using WSS object model

4.1  Using Feature

In the feature, the elements.xml file should be as follows.
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
……………………
……………………
<Receivers ListTemplateId=”100″>
<Receiver>
<Name>VideoAddedEventReceiver</Name>
<Type>ItemAdded</Type>
<SequenceNumber>20000</SequenceNumber>
<Assembly>MyProject.MyModule.Events, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0b231a5ff63cd9fa</Assembly>
<Class>MyProject.MyModule.Events.VideoAddedEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
………………………………
……………………………..
</Receivers>
</Elements>
Any number of receivers can be bound through one feature.
Limitation: Site level events cannot be registered/bound through the feature because we cannot associate a ListTemplateId with a site.

4.2 Using  Content Type

In a content type, the elements.xml file should be as follows.
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
<ContentType ID=”id” Name=”name” Group=”GroupName” Description=”Description of content type” Version=”0″>
<FieldRefs>
<FieldRef ID=”FIELD ID” Name=”FIELD NAME” />
…………………………
…………………………
</FieldRefs>
<XmlDocuments>
<XmlDocument NamespaceURI=”http://schemas.microsoft.com/sharepoint/events“>
<spe:Receivers xmlns:spe=”http://schemas.microsoft.com/sharepoint/events“>
<Receiver>
<Name> VideoAddedEventReceiver </Name>
<Type> ItemAdded </Type>
<SequenceNumber>20000</SequenceNumber>
<Assembly> MyProject.MyModule.Events, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0b231a5ff63cd9fa </Assembly>
<Class> MyProject.MyModule.Events.VideoAddedEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
</spe:Receivers>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>
The same limitation of ‘using feature’ applies to content type also because a content type cannot be associated with a site.
Sequence Number determines when the event receiver should get executed in case if more than one event receivers are about to be executed. An event receiver with greater sequence number gets executed after its counterpart with lesser sequence number.

4.3 Using WSS object model

The below is a sample code how an event receiver is bound with a list.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.Lists[“Video Library”].EventReceivers.Add(
SPEventReceiverType.ItemAdded,
“MyProject.MyModule.Events, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0b231a5ff63cd9fa”,
” MyProject.MyModule.Events.VideoAddedEventReceiver “);
}
In the above code, the custom class ‘VideoAddedEventReceiver’ of type ‘ItemAdded’ is bound with a list named ‘Video Library’.

5. Unbinding SharePoint Event Receiver

• Event receiver bound with the help of content type cannot be unbound.
• If the event receiver was bound with the help of a feature, deactivating the feature would unbind the event receiver from its associated object.
• If the event receiver was bound using WSS object model,
1. Move to the object (site collection or website or list) to which the event receiver is bound.
2. Retrieve the event receiver definition of the intended event receiver.
3. EventReceiverDefinitionObject.Delete().
4. Call the update of that object (site collection or website or list).



















Reference:

http://beginnersbook.com/2013/02/event-receivers-in-sharepoint/

SharePoint WebPart Life-Cycle Events and Event Sequence


Like Asp.Net life cycle there is also Web Part life cycle. So it is better to understand the web part life cycle. I’ve explained some of them which are used by every developer to cover most of the requirements:
OnInit: This method handles initialization of the control.
OnLoad: This event handles the Load event. This is also used for initialize the control but is not intended for loading data or other processing functionality.
CreateChildControls: This is the most popular event in web part life cycle. This creates any child controls. So if you are adding any control to display then you have to write in this method.
EnsureChildControls: This method ensures that CreateChildControls has executed. EnsureChildControls method must be called to prevent null reference exceptions.
SaveViewState: View state of the web part saved.
OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.
Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.
Render: This method is used to render everything.
RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.
OnUnload: Performs the final cleanup.

Reference:

http://geekswithblogs.net/KunaalKapoor/archive/2012/07/18/sharepoint-webpart-life-cycle-events-and-event-sequence.aspx

WebPart Life Cycle


OnInit
In this event the configuration values can be set using a property bag and those that are in the web part task pane are loaded into the web part.
protected override void OnInit(EventArgs e)
{
 
}
LoadViewState
The view state of the web part is populated here.
protected override void LoadViewState(object savedState) //Only at Postback
{

 
}
 
OnLoad
This event is for loading the WebPart such as adding controls.
protected override void OnLoad(EventArgs e)
{
}
CreateChildControls
In this routine control properties and methods previously declared are defined. In most cases, we have to initialize the control's default value (such as Text, Checked, Items, and so on) and activity that is possible to call just at first WebPart load, checking PostBack. The controls specified are created and added to the controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In the case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.
protected override void CreateChildControls()
{
}
OnPreRender
Here we can change any of the web part properties before the control output is drawn. This is the routine where the control's value is kept for the View State.
protected override void OnPreRender(EventArgs e)
{
}
Render
HTML Output is generated.
protected override void Render(HtmlTextWriter writer)
{
}
OnUnload
This is executed when the web part is unloaded.
protected override void OnUnload(EventArgs e)
{
}
Dispose
This to free the memory.
public override void Dispose()
{
}

Reference:

http://www.c-sharpcorner.com/uploadfile/Roji.Joy/webpart-life-cycle/

Connected Web Parts in SharePoint 2010 - an Architectural Framework


This article has been co-authored by Lavanya Kammari (Main Author), Nataraj Yadavalli (Main Author) and Mark Kendall.
Creating an Enterprise Portal can be a daunting task when you are using custom Webparts in just about all cases and you want to be able to communicate with the other web parts, via some sort of custom navigation system. Microsoft has done a good job creating the framework, but not so good of a job explaining how to use the connected Webpart Framework. See this article for a brief overview. http://msdn.microsoft.com/en-us/library/ms469765.aspx.
In this article, we will rely on our experience as a team, who has actually implemented a successful connected Webparts Enterprise Portal, and hope that it will help you implement your own version.
The main advantage of connected Webparts is to exchange data between web parts at run time. For this, we should have at least two web parts one for provider and the other for consumer. Provider web part will pass data to the consumer web part. Here we will explain the required steps to create connectable web parts in Visual Studio 2010 using Visual Webpart template.
Basic Steps
Creating the web part connection interface.
  1. Creating a Web Part by using the Visual Studio Visual Web Part item template.
  2. Creating a provider Web Part that defines a string.
  3. Creating a consumer Web Part that uses and displays the string.
  4. Creating a Web Part page and connecting the provider and consumer Web Parts.
  5. Adding code-behind in Visual Web Parts to handle post back properly
Before we begin with our steps, let’s start by creating an empty solution which will be used later in our steps.
empty-sharepoint-solution
sharepoint-wizard
Step 1: Creating the web part connection interface:
SharePoint uses an interface to communicate/ exchange data between the web parts. Now we will create an interface called ‘iConnectableNavigation’, which has a method to get the selected Category.
Right click on your solution and Click ‘Add new item’ and select ‘Interface’ to create an interface.
sharepoint-new-interface
Once you have created ‘iConnectableNavigation’ interface, add the following code.
iconnectable-interface
Step 2: Creating a Web Part by using the Visual Studio Visual Web Part item template -
In Visual Studio 2010, you can create two types of Web Parts. The first type, Visual web part, creates a user control and deploys this in content Template. Here all controls can be created using the design mode. The other one is a default web part, which inherits from ‘System.Web.UI.WebControls.WebParts’ namespace. Here you have to define all the controls in code behind.
In this article, we are creating ‘Visual Web Parts’ for both provider and consumer.
Step 3: Creating a provider Web Part that defines a string:
Now we create a provider visual web part, which has a drop down of Categories. When user selects an item from the drop down, that value will be provided as string for other webparts which are consumers.
To create a provider web part, right click on the solution and select add a new item. Select “Visual Web Part” template and Name it as “CategoryNavigationWP”. Once you click “Add”, all the required files are created for you.
visual-web-part
connected-web-parts
 
Now open CategoryNavigationWPUserControl.ascx file and add the dropdown and all necessary code.
Add a public method called GetCategoryType which returns the selected drop down item text.
get-category-type
 
Now Open CategoryNavigationWP.cs file and update code as shown below.
category-navigationwp
Note the Attribute on the GetProvider Method. This Attribute must be placed on all webparts that implement the interface. It’s name can be anything you want- in this example Category Provider.
Step 4: Creating a consumer Web Part that uses and displays the string.
Follow the same steps as in Provider web part and create a Visual Web part called ‘CategoryResultsWP’ as a consumer web part and update code as shown below.
visual-web-part1
category-results-wp
category-results-wp1
Step 5: Creating a Web Part page and connecting the provider and consumer Web Parts.
Once you add all your code, compile and deploy your solution to SharePoint site.
Now go to your site page and edit to add the web parts. Once you add your web parts and connected your web parts as shown below, it is time for testing. (Or you can add a new Webparts page)
Two new Webparts will appear in your custom section when you click Add Webpart: Place them on the page as shown below: When you have both of the Webparts on the Webparts page, click on the dropdown on the CategoryResultsWP and select connection. Get category results from, CategoryNavigationWP and the connection will be established. Now you can select from the dropdown and get the results that you would expect. (See screenshots below)
CategoryNavigationWP
add-navigation-webpart
CategoryResultsWP
add-results-webpart
webpart-saveclose
When you are done, you will end up with 2 webparts on a webparts page that will communicate with each other as you make click on the dropdowns. You can have as many webparts as you want on a webparts page that communicate with each other, as long as you implement the correct interfaces- as this article explains.
webpart-communication
multiple-webpart-communication
Step 6: Adding code-behind in Visual Web Parts to handle post back properly.
There are a couple of points to note when you are trying to use connected web parts with Post back.
  • It is always better to call “EnsureChildControls” in Web part OnInit overload method. OnInit method will make sure your view state is loaded at time of control initialization.
  • Call your user control method during the OnPreRender method overload. When you have complex controls or multiple controls to load, it is always better to call during the Pre Render instead of Render Contents method.
Summary:
Congratulation, you’re on your way to creating a framework for your next Enterprise SharePoint rollout which will enable you to connect to all of your web parts on a typical web parts page.
The entire source code of this article can be downloaded over here
Note: After downloading the source code, when you open the VS 2010 project, you must set the SharePoint URL as shown below- right mouse click on ConnectedWebParts and select properties:
set-sharepoint-url

Reference:

http://www.dotnetcurry.com/showarticle.aspx?ID=678

SharePoint 2010 - Connected Web Parts


In this article we can explore Connected Web Parts which is an advanced SharePoint Web Part feature. The connected web parts denote communication between 2 web parts.

CntWbShare1.jpg

The connected web part resolves the following requirements:

  • Master Web Part and Slave web part data exchange
  • Data Selection and Data Display web part communication
Summary of the application is:
  • There are 2 web parts
  • Web Part 1 has a drop down list for selecting Car
  • Web Part 2 displays the car picture based on selection
Steps Involved

Following are the steps involved in creating connected web parts:

  1. Create Project
  2. Create Communication Interface
  3. Create Web Part 1 (Provider) implementing Interface
  4. Create Web Part 2 (Consumer)
  5. Build and Deploy
Create Project

We can experiment with a Car showcase application where there are 2 web parts.

  • The first web part allows selecting a Car from the drop down list.
  • The second web part displays the image of the car.
to begin, create a new Web Part project in Visual Studio.

CntWbShare2.jpg

Remove the default VisualWebPart1 web part. We will be adding our own web parts.

Create Interface

For communication between the 2 web parts we need to create an interface. Please create the following interface, which returns the selected Car name:
public interface ICar{
    string Car { get; }
}


Create Provider Web Part implementing Interface

Now you can create a new web part named CarSelectionWebPart. Expand the webpart item and in the User Control (CarSelectionWebPartUserControl.ascx) class file:

  1. Add a drop down list control
  2. Place the following code
public partial class CarSelectionWebPartUserControl : UserControl{
    protected void Page_Load(object sender, EventArgs e)

    {
        if (!this.IsPostBack)
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Camry");
            DropDownList1.Items.Add("Figo");
            DropDownList1.Items.Add("Diablo");
        }
    }
    // Property to expose selected car outside    public string Car
    {
        get;
        set;
    }
    // Set the Car property    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedItem != null)
            Car = DropDownList1.SelectedItem.Text;
    }
}


In the CarSelectionWebPart.cs (web part class file) add the following code:
 
// Property to return the selected Car
public string Car
{
    get
    {
        return (_control as CarSelectionWebPartUserControl).Car;
    }
}

// Special Purpose Attribute to denote ICar interface is provided
[ConnectionProvider("Car")]
public ICar GetCar()
{
    return this;
}
The ConnectionProvider attribute and the interface of the method denotes that this web part provides data for ICar interface. The Connection Provider also says that the name is Car (in string).

Create Consumer Web Part

Now we can create the consumer web part which will get the selected Car to display the car picture. Add a new web part and name it CarDisplayWebPart. Place an image control on the user control of the web part. In the class view of the user control add the following method:
 
// Set the image to url
public void SetImage(string car)
{
    if (car == "Camry")
        Image1.ImageUrl = "/_layouts/images/ConnectedWebParts/Camry.png";

    else if (car == "Figo")
        Image1.ImageUrl = "/_layouts/images/ConnectedWebParts/Figo.png";
           
    else if (car == "Diablo")
        Image1.ImageUrl = "/_layouts/images/ConnectedWebParts/Diablo.png";
}

Now add Images Mapped Folder and place 3 image files (Camry.png, Figo.png, Diablo.png) in the folder as shown below:

CntWbShare3.jpg

Build and Deploy

Now build the project and use the Deploy command. Open the SharePoint site in edit mode and add the above 2 web parts into it. You are now ready with the following 2 web parts.

CntWbShare4.jpg

Set Connection

Use the context menu of CarDisplayWebPart to set the connection to provider web part.

CntWbShare5.jpg

Testing the Web Parts

Now stop editing the web page and refresh the site. Select a car from the first web part and the car picture is displayed on the second web part.

CntWbShare6.jpg

This concludes our article on Connected Web Parts creation.

Debugging the Web Parts

You can debug the application, by executing the project in Debug mode. Any break points set will be executed.

CntWbShare7.jpg

References
http://msdn.microsoft.com/en-us/library/ms469765.aspx
http://rtmgroupq8.com/en/add-image-to-sharepoint-visual-web-part

Summary

In this article we have explored the Connected Web Parts feature of SharePoint Web Parts. In real-world scenarios there could be multiple web parts communicating with each other through connected web parts. SharePoint also supports AJAX enabled web parts which provide a better communication between web parts. The attachment contains the source code of the web parts we discussed.


Reference:

http://www.c-sharpcorner.com/UploadFile/40e97e/sharepoint-2010-connected-web-parts/


Excellent Article by Raza Fayyaz

When you are done developing a WebPart, you need to deploy it to the SharePoint server. However, depending on your server setup, you may have to use specific deployment methodology and that is why it is important to know your options. This post describes different ways to achieve this goal.



Basic understanding

Whatever method you use to develop your WebPart, you will always end up with a WebPart DLL and in some cases you will have WSP file (both of these files are in debug folder of your project). It is the DLL file that plays a key role in getting your WebPart inside SharePoint server.

Ways to deploy a WebPart

There are four ways we can deploy a WebPart on SharePoint server that I will cover in this post:

  1. Using Visual Studio to deploy the solution
  2. Manually moving the DLL to the server
  3. Uploading WSP to SharePoint server
  4. Deploying through command prompt 

http://1.bp.blogspot.com/-9q1EXfN_yLI/UKPcQd_64HI/AAAAAAAABDA/sPWQO5X9cUI/s1600/11-14-2012+12-58-15+PM.png



Pre-Requisites

I am assuming that you are all done with the development and are now ready to deploy. In these examples I have a project name "FeedbackWP" that I need to deploy.

Deploying through Visual Studio

Once the coding is complete, click on build > deploy



In the output window you should see the deployment success status.


 http://2.bp.blogspot.com/-fv3DI1HKoJ0/UKGpgUhfRzI/AAAAAAAAA7E/bgasRLhAPcc/s1600/dep01.png


 For next steps please look at "After you webpart is deployed" section at the end of this post.




 Deploying by manually moving the DLL


Build the solution





 http://3.bp.blogspot.com/--Mi1xtcfe0c/UKMHGq6yicI/AAAAAAAAA_4/kFLQfRL5AfA/s1600/11-13-2012+8-31-04+PM.png



 If no error returned by the compiler, copy the DLL from your project bin > Debug directory to the bin directory of your WSS site (C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin).





Go to (C:\inetpub\wwwroot\wss\VirtualDirectories\80\) and modify the Web.Config file for the WSS site to declare the custom web part as a safe control by adding the following code within the <SafeControls> tag.

<SafeControl Assembly="DLL-Name-Here" Namespace="DLL-Name . NameSpaceHere" TypeName="*" Safe="True" />

In my case my dll name is feedBackWP and the namespace of my webpart is InputForm; so my SafeControl entry looks like:

<SafeControl Assembly="feedBackWP" Namespace="feedBackWP.InputForm" TypeName="*" Safe="True" />

And my webconfig looks like the image below:

http://1.bp.blogspot.com/-jiCymaJvo7w/UKMHLijKW_I/AAAAAAAABAQ/5Qedd6zia3g/s1600/11-13-2012+9-09-33+PM.png






 Now we need to add this webpart to our Sharepoint gallery.

Click on Site Actions -> Site Settings -> Web Parts.






 http://3.bp.blogspot.com/-UtadCI7yPqo/UKMHNj21jEI/AAAAAAAABAY/D0vW9LlSSLI/s1600/11-13-2012+9-11-59+PM.png



 From Web Parts page click on Documents > New Document


http://1.bp.blogspot.com/-nE0BLa5zFt0/UKMHO93alWI/AAAAAAAABAg/zvEsLc7L6t4/s1600/11-13-2012+9-12-51+PM.png






http://1.bp.blogspot.com/-EiF_7QR8w08/UKMHQhr1FWI/AAAAAAAABAo/vP6As8k8vaQ/s1600/11-13-2012+9-13-30+PM.png




New Document will bring up a pop-up window. This window should have your new web part listed. Select your webpart from the list and click on Populate Gallery.



If the import is successful, you will see the web part in Web part gallery list.


http://3.bp.blogspot.com/-vILaBOdvRLU/UKMHddpRShI/AAAAAAAABBA/oTuzGPqLaqk/s1600/11-13-2012+9-14-46+PM.png






 For next steps please look at "After you webpart is deployed" section at the end of this post.




Deploying by uploading WSP to SharePoint server

Build the solution














http://3.bp.blogspot.com/--Mi1xtcfe0c/UKMHGq6yicI/AAAAAAAAA_4/kFLQfRL5AfA/s1600/11-13-2012+8-31-04+PM.png


 If no error returned by the compiler, you will have WSP file in your project bin > Debug.


  Open Sharepoint and click on Site Actions -> Site Settings -> solutions.

 http://3.bp.blogspot.com/-UvVvC5aXRDY/UKMHie4wZ4I/AAAAAAAABBQ/H30usUemCKY/s1600/11-13-2012+9-11-27+PM.png




 http://4.bp.blogspot.com/-WJ1sGlPz2i0/UKPYWvIRMZI/AAAAAAAABBw/73In8RejR0g/s1600/11-14-2012+12-34-53+PM.png


 From solutions page click on solutions on top and after clicking it, you should see upload solution tab.


 http://4.bp.blogspot.com/-Z1MKNPd9w5Y/UKPYXJyDfTI/AAAAAAAABB4/6MjW-d-5ZdQ/s1600/11-14-2012+12-37-05+PM.png



 http://1.bp.blogspot.com/-Bb-cQP-vqNU/UKPYX9BiAlI/AAAAAAAABCA/PJL_6Yz8EEA/s1600/11-14-2012+12-37-19+PM.png
 Click on upload solution and it will bring up a popoup to upload your webpart.



 http://4.bp.blogspot.com/-HpiW-CeEyyQ/UKPYYntxTXI/AAAAAAAABCI/eEChYTQ7E3A/s1600/11-14-2012+12-38-34+PM.png


 Upload your WSP file.


 http://1.bp.blogspot.com/-rzFyTv3_ubU/UKPYZlQHpkI/AAAAAAAABCQ/Id6-yOjzfXs/s1600/11-14-2012+12-39-22+PM.png


 If uploading is successfull, you should see the webpart appear in the solutions list.


 http://1.bp.blogspot.com/-1fOANA4FP7w/UKPYdQ4RuQI/AAAAAAAABCY/oXQB0ysG7YE/s1600/11-14-2012+12-39-51+PM.png


Activate the solution and thats it.


 http://4.bp.blogspot.com/-Smn0GEJ5BdY/UKPYeB3dHLI/AAAAAAAABCg/GjbI1Sktl0s/s1600/11-14-2012+12-40-47+PM.png






http://2.bp.blogspot.com/-NPyCJYMEzR4/UKPYe8kHK1I/AAAAAAAABCo/eEOY19EMXS0/s1600/11-14-2012+12-41-07+PM.png


 For next steps please look at "After you webpart is deployed" section at the end of this post.




Deploying through command prompt

Build the solution







http://3.bp.blogspot.com/--Mi1xtcfe0c/UKMHGq6yicI/AAAAAAAAA_4/kFLQfRL5AfA/s1600/11-13-2012+8-31-04+PM.png


 If no error returned by the compiler, you will have WSP file in your project bin > Debug.


Copy the wsp file on the server and open up a command line and navigate to the 12-hive bin folder.
(my 12-hive bin folder is C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN)



 http://2.bp.blogspot.com/-C1nBxCWcvBI/UKPmVVQPsjI/AAAAAAAABDY/wq6-9LdRm6Y/s1600/11-14-2012+1-29-26+PM.png



 Enter the following commands :

stsadm -o addsolution -filename WSP FILE NAME WITH LOCATION

stsadm -o deploysolution -name WSP FILE NAME -immediate -allowGacDeployment -url  SITEURL  



So in my case these commands become:

stsadm -o addsolution -filename c:/feedBackWP.wsp

stsadm -o deploysolution -name feedBackWP.wsp -immediate -allowGacDeployment -url ht
tp://bk-laptop-hp/



 http://3.bp.blogspot.com/-o7qoxWaTbzs/UKPmWgKUyeI/AAAAAAAABDg/7o-qbXGY3c8/s1600/11-14-2012+1-31-07+PM.png



 For next steps please look at "After you webpart is deployed" section.

After your Webpart is deployed

Go to the SharePoint site and click on Site Action > New Page.

 http://4.bp.blogspot.com/-YVsRDPmTLZA/UKGpwipNQeI/AAAAAAAAA7M/2Elzv3nnGDA/s1600/dep1.png



 http://1.bp.blogspot.com/-0UHB-KxrSBk/UKGqG4Zve0I/AAAAAAAAA7U/r1VyZy8G-Gg/s1600/dep2.png



 http://1.bp.blogspot.com/-MVeJYuv8-Q8/UKGqJsAN8rI/AAAAAAAAA7c/yrVKQLW6ADQ/s1600/dep3.png


 From new page click on Insert and then on WebPart.

 http://2.bp.blogspot.com/-4BUwwuWbt00/UKGqTSZmAEI/AAAAAAAAA7k/-MN3qXpBkuQ/s1600/dep4.png


 http://2.bp.blogspot.com/-LpS-ltYwZcM/UKGqmC7PAoI/AAAAAAAAA7s/c4-XnbhuUH0/s1600/dep5.png




 From WebPart list click on custom (NOTE: In some cases this is miscellaneous instead of custom). This should bring up our WebPart on the right hand side.


 http://1.bp.blogspot.com/-5j68o3_OM7Y/UKGqsSBVQAI/AAAAAAAAA70/3UHNFuiAoE4/s1600/dep6.png




 With the WebPart selected click on the add button.



 http://1.bp.blogspot.com/-BcuQ7QKHAoY/UKGrRTRWPHI/AAAAAAAAA8E/8TGuMbu5tSI/s1600/dep8.png











Reference:

http://www.razafayyaz.com/2012/11/different-ways-to-deploy-webpart-on.html