Friday, June 28, 2013

STAPLING .. FEATURE STAPLING

Feature stapling is a technique that allows a feature to be stapled to a site definition by using another feature called  the "stapler" feature that defines which features are attacched to which site definition.
This allows for a feature to be automatically activated on a site created from a site definition without the need to modify the definition files (onet.xml). 

Causes the attachment of a Feature to all new instances of sites that use a given site definition, without modifying the site definition or creating code routines to activate the Feature on each site. Also known as a feature site template association,
Feature Stapling can be created for the site definition that is already in use. Feature Stapling has two features.
  1. A Stapler feature: that staples another feature to the site definition
2        2 .    A Staplee feature: that which will be stapled













Scenario :
Suppose, we need to create a  custom list by default whenever a  new site is created using the Team Site template.
What Shall we do ?

GO FOR FEATURE STAPLING



Steps involved


  1. Create an  Empty SharePoint Project
  2. Create a feature staplee
  3. Create the feature stapler
  4. Create FeatureAssociation.xml
  5. Deploy the solution
Create an Empty SharePoint Project
  1. Open Visual Studio 2010
  2. Go to the File tab, click on "New" and then click on "Project".
  3. In the New Project dialog box, expand the Visual C# node, and then select the SharePoint 2010 node.
  4. In the Templates pane, select "Empty SharePoint Project".

  5. Share1.jpg
  6. Enter the Name as FeatureStapling and then click "OK".                                                                                  Create a feature STAPLEE

Lets Create a custom List using the STAPLEE FEATURE
  1. Share3.jpg
  2. In the Solution Explorer, right-click on the Feature folder and then click on "Add Feature". 
  3. Double-click on the feature and enter the Title and Description for the feature. 
  4. Select the scope as web from the drop down list.
  5. Right-click on CreateListFeature and then click on the Add Event receiver
  6. Share5.jpg


  7.  
  8. Double-click on CreateListFeature.EventReceiver.cs and write code to create a custom list in the activated event  

Create feature stapler
In this section you will see how to create a feature stapler that is used to staple the CreateListFeature to the site definition.

  1. In the Solution Explorer, right-click on the Feature folder and then click on "Add Feature".

    Share7.jpg
     
  2. Rename the feature to "FeatureStapler".

    Share8.jpg
     
  3. Double-click on the feature and enter the Title and Description for the feature.

    Share9.jpg
     
  4. Select the scope as WebApplication from the drop down list.
Create FeatureAssociation.xml
In this section you will see how to create the XML file to associate the feature to the site definition.

  1. In the Solution Explorer, right-click on the project, click on "Add" and then click on "New Item".
  2. Select the "Empty Element" template, enter the Name and then click on "Add".

    Share10.jpg
     
  3. Double-click on Elements.xml and replace with the following:

    Share11.jpg

    Id - CreateListFeature feature Id.

    Template Name: To which site template the feature should be associated (the format should be <site template name><configuration number>).
     
  4. Ensure this file is added to the FeatureStapler feature (double-click on the FeatureStapler feature and see whether in the "Items in the feature" window the Elements.xml file is available).

    Share12.jpg
Deploy the solution
Right-click on the solution and then click on "Deploy Solution".
Check whether the feature stapler is activated in the web application:

  1. Open Central Administration.
  2. Click on Manage Web Applications that is available in the Application Management section.
  3. Select the web application and then click on "Manage Features" in the ribbon interface.

    Share13.jpg
     
  4. Check whether the Feature Stapler feature is activated.


  1. Share15.jpg

Wednesday, June 26, 2013

Simple steps to add a ".dll" file into the Global Assembly Cache in c#

Step 1 : In your project "Add reference" to the .dll file you want to install in GAC
Step 2 : Form the Refrences; Right click on the particular .dll file and take properties
Step 3 : Change the property "Copy Local" to "True"
Step 4 : Build and deploy using wspBuilder ; Done

Step 5 : For verification just check in manifest file whether the path exists or not and also in "C:\Windows\assembly".

Delegate Controls in SharePoint

"Delegate?"

The answer is "Its a Pointer to Function / Method",  Delegate Control is a pointer to a Control which can be replaced at runtime based on Feature Activation or Deactivation.

Contains a certain predefined element of the SharePoint Products and Technologies environment to replace with another control through a SharePoint Feature.

Real World Example

A user wants to replace the built-in search control with a richer version. He creates a Feature that includes a delegate control to override the delegate control placeholder.

SharePoint Delegate control is a mechanism that we can inject a code or control to the SharePoint Master page with out touching any any code in the SharePoint Master page.

is a container type control which can holds child controls on it


Essentially the Delegate Control provides an alternative to adding user controls and server controls to a .aspx page in the normal way. By this, I mean adding the control to the page by dragging from the toolbox in the development environment or by adding the appropriate markup manually. Instead, with a Delegate Control all we do is add the markup to instantiate a Delegate Control instance, and use a Feature to specify separately which control should actually be loaded. What this effectively gives us is the ability to control what controls are used on a page without having to directly modify and redeploy master pages/page layouts. This extra level of abstraction can be quite powerful, since any feature scope can be used with the Delegate Control.

 Here's how it's used:
The Delegate Controls comes into picture when want to brand a SharePoint Site. The delegate control acts like a container control which encapsulates default content (set of child controls inside it). The default content (set of child controls associated with delegate) can be substituted by a specific control, by creating a feature. The ability to override or substitute the delegate controls brings the power & flexibility to brand SharePoint Sites.

The out-of-box SharePoint Foundation Master Page defines many controls like Top Navigation Data Source, Left Navigation Data Source, Search Box and Additional Page Head etc as delegate controls. The list is illustrated below :-
<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" 
AllowMultipleControls="true"/>
<SharePoint:DelegateControl runat="server" ControlId="GlobalNavigation" />
<SharePoint:DelegateControl runat="server" ID="GlobalDelegate0" ControlId="GlobalSiteLink0" />

<SharePoint:DelegateControl ControlId="GlobalSiteLink2" ID="GlobalDelegate2" Scope="Farm"
 runat="server" />

<SharePoint:DelegateControl runat="server" ControlId="PublishingConsole" 
Id="PublishingConsoleDelegate">
</SharePoint:DelegateControl><SharePoint:DelegateControl ControlId="GlobalSiteLink3" Scope="Farm" 
runat="server" />
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4" />

<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" 
Id="topNavigationDelegate"/>
    

The above listed delegate controls can be substituted at runtime to achieve custom branding. Let’s try to replace the Small Search Input box and see how the delegate control helps for this process. The whole idea is to define a feature for the Custom User Control with same control id mentioned in delegate and the lowest possible sequence number.
Here are the steps below :-

File ---> New Project ---> Empty SharePoint Project
pic1
Right Click Project –> Add New item –> User Control . Name it as ‘ReplaceSearchBox’
image
It automatically creates control templates folder and places the user control underneath that. Create any arbitrary control inside the user control. For the illustration purpose, I’ll add a Calendar Control inside the user control, to visually show a difference how the page looks after the delegate substitution.
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
It automatically creates control templates folder and places the user control underneath that.

Right Click Features –> Add Feature
Set the Feature Scope at Site (site-collection level)
Right Click Solution ---> Add New Item –> Empty Element
We’d be leveraging Elements.xml file for the delegate substitution process. Before jumping on to the substitution lets understand how the out-of-box Search Box is defined using Feature.

searchbox
The Search Box is defined in both the Features ‘OSearchBasicFeature’ and ‘OSearchEnhancedFeature’ in the location 
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES
The definition looks like the following :-
 
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Control 
        Id="SmallSearchInputBox" 
        Sequence="50"
        ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" 
ControlAssembly="Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, 
PublicKeyToken=71e9bce111e9429c">

    <Property Name="GoImageUrl">/_layouts/images/gosearch15.png</Property>
    <Property Name="GoImageUrlRTL">/_layouts/images/gosearchrtl15.png</Property>
    <Property Name="GoImageActiveUrl">/_layouts/images/gosearchhover15.png</Property>
    <Property Name="GoImageActiveUrlRTL">/_layouts/images/gosearchrtlhover15.png</Property>
    <Property Name="DropDownMode">ShowDD</Property>
        <Property Name="SearchResultPageURL">/_layouts/osssearchresults.aspx</Property>
    <Property Name="ScopeDisplayGroupName"></Property>
    <Property Name="FrameType">None</Property>
    </Control>    
</Elements>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 
Here the Id & Sequence number of the control plays an important role. 
To substitute this out-of-box SmallSearchInput box, Let’s define Elements.xml file for Feature. The id of the control should match with id of control to be replaced. 
The Sequence number should be less than the sequence number of the out-of-box control. In this case we’re assigning sequence number as 10, so that the control with the lowest
 sequence number gets precedence.
 
    <Control Id="SmallSearchInputBox" Sequence="10"
      ControlSrc ="~/_controltemplates/ReplaceSearchBox/ReplaceSearchBox.ascx">        
    </Control></Elements>
 
Since we’re using an user control for substitution, we need to make sure that ControlSrc attribute is defined. There is no need to define ControlClass and ControlAssembly attribute here. 
I did define all the 3 attributes, but the substitution was not happening. I’ve learnt that it’s enough to define the ControlSrc attribute itself. Do not define all 3  attributes for user control, 
the substitution will not happen. If you are using Custom Control, it makes sense to use ControlClass and ControlAssembly attribute.
The final Solution Package looks like the following :-
image


Build the Project, Package it and Deploy.
Now you can see the the custom user control with Calendar replaces the Delegate control.
Delegate Substitution

Restrict the insertion of users to a sharepoint List -- Out of the Box (Add only users in particualr groups to a list.)

Scenario : There is a list called Subsite Owners . And i need to add only the users who belong to a particular sharepoint group to the list Subsite Owners . How do i do it?


Inorder to achieve this , we would need to create a people picker field( the field wich will hold the user names) . The choose from option allows you to sepcify the user group from which the users can be added from .

EG:  I need the user to be added only from a group called subsite9 owners ?

Solution : Create a new column as a person or Group field  as shown below

Then in the Choose from option select the sharepoint group from which you want the users to be added . This will only allow the users in the selected group to be added to the list.


Monday, June 24, 2013

Sharepoint Webparts -- All you need to know about webparts !!!!!!

What is web part? 
Web Parts are the fundamental building blocks for Share Point user interface, and with them we can build and integrate many different types of applications.

Webparts can be considered as reusable widgets (similar to the yahoo ones) which work independently (though they can communicate) and are individually configurable. This makes the task of showing up of different logical sections on the same web page easier; especially while doing independent development. Brought out initially with Sharepoint 2003, it was supported in ASP.NET extensively and now in MOSS 2007 .

Web Parts are componentized, self-contained packages of user interface that can be dropped into place on SharePoint Web Part pages to provide discrete sets of functionality to users.

How many types of webparts available? 
These are the following types of webpart :
1. Content Editor Web Part
2. Data View Web Part
3. List View Web Part
4. Image Web Part
5. Members Web Part
6. Page Viewer Web Part

While creating a Web part, which is the ideal location to Initialize the web controls? 
Override the CreateChildControls method to include web controls. You can control the exact rendering of your controls by calling the Render method.

What are the two base classes a WebPart can inherit from? 
There are two base classes that a WebPart consumed by SharePoint can inherit from, either the SharePoint WebPart Base class or the ASP.NET 2.0 WebPart base class.

What are the differences between the SharePoint WebPart Base class and ASP.NET 2.0 WebPart base class? 
Microsoft.SharePoint.WebPartPages.WebPart base class is meant for backward compatibility with previous versions of SharePoint. The benefit of using the SharePoint WebPart base class is it supported:
1. Cross page connections
2. Connections between Web Parts that are outside of a Web Part zone
3. Client-side connections (Web Part Page Services Component)
4. Data caching infrastructure
ASP.NET 2.0 WebParts are generally considered better to use because SharePoint is built upon the ASP.NET 2.0 web architecture.

What are the inherit benefits of using ASP.NET 2.0 WebPart base class? 
Inheriting from the ASP.NET 2.0 base class offers you features that inherit to ASP.NET 2.0, such as embedding resources as opposed to use ClassResources for deployment of said types.

What is the WebPartManager sealed class? What is its purpose? 
The WebPartManager sealed class is responsible for managing everything occurring on a WebPart page, such as the WebParts (controls), events, and misc. functionality that will occur in WebPartZones. For example, the WebPartManager is responsible for the functionality that is provided when you are working with moving a WebPart from WebPartZone to WebPartZone. It is known as the �the central class of the Web Part Control Set.

What is a web part zone? 
Web part zones are what your web parts reside in and help categorize your web parts when designing a page.
How you debug custom webpart in MOSS?

At that point you must manually attach the debugger to the process running the code.  The process you will need to attach to is the w3wp.exe process. 
To do this:
1. Go to Debug -> Attach to Process.
2. Check the Show processes from all users and Show processes in all sessions checkbox.
3. Scroll down to the w3wp process and click Attach.


Which class you inherit for creating a webpart?

System.Web.UI.WebParts.WebPart
Here is the example:
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Demo.Webparts
{
public class demowebpart : System.Web.UI.WebControls.WebParts.WebPart
{

What are the main methods to be override  while creatng custom webpart?
CreateChildControls()
RenderControl(HtmlTextWriter writer)
The CreateChildren Control is same as in .Net 1.1, that it would create and add controls to this Web Part Class,. In this case I have only added a WebControl.Calender Object. The RenderControl Method is an override for the WebPart Base Class and calls the RenderChildren Method, this causes the Children Controls to be rendered on the Particular HtmlTextWriter passed as a parameter to the method.

What is the procedure for deploying custom webpart?

http://www.developer.com/net/asp/article.php/3620316


What is the GAC?

The GAC stands for the global assembly cache. It is the machine wide code cache which will give custom binaries place into the full trust code group for SharePoint. Certain SharePoint assets, such as Feature Receivers need full trust to run correctly, and therefore are put into the GAC. You should always try to avoid deployment to the GAC as much as possible since it will possibly allow development code to do more than it was intended to do.

What is strong naming (signing) a WebPart assembly file mean? 

Signing an assembly with a strong name (a.k.a strong naming) uses a cryptographic key pair that gives a unique identity to a component that is being built. This identity can then be referred throughout the rest of the environment. In order to install assemblies into the GAC, they must be strongly named. After signing, the binary will have a public key token identifier which can be use to register the component in various other places on the server.

What are safe controls, and what type of information, is placed in that element in a SharePoint web.config file?

When you deploy a WebPart to SharePoint, you must first make it as a safe control to use within SharePoint in the web.config file. Entries made in the safe controls element of SharePoint are encountered by the SharePointHandler object and will be loaded in the SharePoint environment properly, those not will not be loaded and will throw an error. In the generic safe control entry (this is general, there could be more), there is generally the Assembly name, the namespace, the public key token numeric, the typename, and the safe declaration (whether it is safe or not). There are other optional elements.

What is the CreateChildControls() method? How can you use it to do something simple like displaying a Label control?
The CreateChildControls method in WebParts is used to notify the WebPart that there are children controls that should be output for rendering. Basically, it will add any child ASP.NET controls that are called instantiating each control with its relevant properties set, wire any relevant event handlers to the control, etc. Then the add method of the control class will add the control to the controls collection. In the relevant WebPart render method, the EnsureChildControls method can be called (or set to false if no child controls should be called) to ensure that the CreateChildControls method is run. When using CreateChildControls it implies that your WebPart contains a composition of child controls.

In order to create something like a label control in Create, you would create a new label control using the new keyword, set the various properties of the control like Visible=True and ForeColor = Color.Red, and then use Controls.Add(myLabelControl) to add the control to the controls collection. Then you can declare EnsureChildControls in the Render method of the WebPart.

What does the RenderContents method do in an ASP.NET 2.0 WebPart? 
The render contents method will render the WebPart content to the writer, usually an HtmlTextWriter since WebParts will output to an HTML stream. RenderContents is used to tell how the controls that are going to be displayed in the WebPart should be rendered on the page.

What is the WebPartManager sealed class? What is its purpose? 

The WebPartManager sealed class is responsible for managing everything occurring on a WebPart page, such as the WebParts (controls), events, and misc. functionality that will occur in WebPartZones. For example, the WebPartManager is responsible for the functionality that is provided when you are working with moving a WebPart from WebPartZone to WebPartZone. It is known as the "the central class of the Web Part Control Set."

While creating a Webpart, which is the ideal location to Initialize my new controls ?

Override the CreateChildControls method to include your new controls. To make sure that the new controls are initialized.. call 'EnsureChildControls' in the webparts Render method. You can control the exact Rendering of your controls by calling the .Render method in the webparts Render method.


SharePoint 2010 - Out of box webparts

Out Of Box (OOB) Webparts
These are the basic in-built components in SharePoint for displaying and managing list data without the need of any custom development. Not all of them will be available depending upon the version of SharePoint installed.

List of OOB Webparts in SharePoint 2010
Following is the list of OOB webparts in SharePoint 2010 along with the category.

List and Libraries
Announcements – Use this list to track upcoming events, status updates or other team news
Calendar – Use the Calendar list to keep informed of upcoming meetings, deadlines, and other important events
Links - Use the Links list for links to Web pages that your team members will find interesting or useful
Shared Documents – Share a document with the team by adding it to this document library
Site Assets – Use this library to store files which are included on pages within this site, such as images on Wiki pages.
Site Pages – Use this library to create and store pages on this site
Tasks – Use the Tasks list to keep track of work that you or your team needs to complete
Team Discussions – Use the Team Discussion list to hold newsgroup-style discussions on topics relevant to your team

Business Data
Business Data Actions – Displays a list of actions from Business Data Connectivity
Business Data Connectivity Filter – Filters the contents of Web Parts using a list of values from the Business Data Connectivity
Business Data Item – Displays one item from a data source in Business Data Connectivity
Business Data Item Builder – Creates a Business Data item from parameters in the query string and provides it to other Web Parts
Business Data List – Displays a list of items from a data source in Business Data Connectivity
Business Data Related List – Displays a list of items related to one or more parent items from a data source in Business Data Connectivity
Chart Web Part – Helps you to visualize your data on SharePoint sites and portals
Excel Web Access – Use the Excel Web Access Web Part to interact with an Excel workbook as a Web page
Indicator Details – Displays the details of a single Status Indicator. Status Indicators display an important measure for an organization and may be obtained from other data sources including SharePoint lists, Excel workbooks, and SQL Server 2005 Analysis Services KPIs.
Status Lists – Shows a list of Status Indicators. Status Indicators display important measures for your organization, and show how your organization is performing with respect to your goals.
Visio Web Access – Enables viewing and refreshing of Visio Web Drawings

Content Rollup
Categories – Displays categories from the Site Directory
Content Query – Displays a dynamic view of content from your site
Relevant Documents – Displays documents that are relevant to the current user
RSS Viewer – Displays an RSS feed
Site Aggregator – Displays sites of your choice.
Sites In Category – Displays sites from the Site Directory within a specific category
Summary Links – Allows authors to create links that can be grouped and styled
Table Of Contents – Displays the navigation hierarchy of your site
Web Analytics web Part – Displays the most viewed content, most frequent search queries from a site, or most frequent search queries from a search center
WSRP Viewer – Displays portlets from web sites using WSRP 1.1
XML Viewer – Transforms XML data using XSL and shows the results

Filters
Choice Filter – Filters the contents of Web Parts using a list of values entered by the page author
Current User Filter – Filters the contents of Web Parts by using properties of the current user
Date Filter – Filter the contents of Web Parts by allowing users to enter or pick a date
Filter Actions – Use the Filter Actions Web Part when you have two or more filter Web Parts on one  Web Part Page, and you want to synchronize the display of the filter results
Page Field Filter – Filters the contents of Web Parts using information about the current page
Query String (URL) Filter – Filters the contents of Web Parts using values passed via the query string
SharePoint List Filter - Filters the contents of Web Parts by using a list of values
SQL Server Analysis Services Filter – Filters the contents of Web Parts using a list of values from SQL Server Analysis Services cubes
Text Filter – Filters the contents of Web Parts by allowing users to enter a text value

Forms
HTML Form Web Part – Connects simple form controls to other Web Parts
InfoPath Form Web Part – Use this Web Part to display an InfoPath browser-enabled form

Media and Content
Content Editor – Allows authors to enter rich text content
Image Viewer – Displays a specified image
Media Web Part – Use to embed media clips (video and audio) in a web page
Page Viewer - Displays another Web page on this Web page. The other Web page is presented in an IFrame
Picture Library Slideshow Web Part – Use to display a slideshow of images and photos from a picture library
Silverlight Web part – A web part to display a Silverlight application

Outlook Web App
My Calendar – Displays your calendar using Outlook Web Access for Microsoft Exchange Server 2003 or later
My Contacts – Displays your contacts using Outlook Web Access for Microsoft Exchange Server 2003 or later
My Inbox – Displays your inbox using Outlook Web Access for Microsoft Exchange Server 2003 or later
My Mail Folder – Displays your mail folder using Outlook Web Access for Microsoft Exchange Server 2000
My Tasks – Displays your tasks using Outlook Web Access for Microsoft Exchange Server 2003 or later

PerformancePoint
PerformancePoint Filter – This web part displays PerformancePoint filters. Filters may be linked to other web parts to provide an interactive dashboard experience. Filter types include lists and trees based on a variety of data sources
PerformancePoint Report – This web part displays PerformancePoint reports. Reports may be linked to other web parts to create an interactive dashboard experience. Report types include: Analytic charts & grids, Strategy Maps, Excel Services, Reporting Services, Predictive Trend charts, and web pages
PerformancePoint Scorecard – This web part displays a PerformancePoint scorecard. Scorecards may be linked to other web parts, such as filters and reports, to create an interactive dashboard experience.
PerformancePoint Stack Selector – This web part displays a PerformancePoint Stack Selector. All PerformancePoint web parts, such as filters and reports, contained in the same zone will be automatically stacked and selectable using this web part.

Search
Advanced Search Box – Displays parameterized search options based on properties and combinations of words.
Dual Chinese Search – Used to search Dual Chinese document and items at the same time.
Federated Results – Displays search results from a configured location
People Refinement Panel – This webpart helps the users to refine people search results
People Search Box – Presents a search box that allows users to search for people
People Search Core Results – Displays the people search results and the properties associated with them.
Refinement Panel – This webpart helps the users to refine search results
Related Queries – This webpart displays related queries to a user query
Search Action Link – Displays the search action links on the search results page
Search Best Bet – Displays high-confidence results on a search results page.
Search Box – Displays a search box that allows users to search for information.
Search Core Results – Displays the search results and the properties associated with them
Search Paging – Display links for navigating pages containing search results.
Search Statistics – Displays the search statistics such as the number of results shown on the current page, total number of results and time taken to perform the search.
Search Summary – Displays suggestions for current search query
Search Visual Best Bet – Displays Visual Best Bet
Top Federated Results – Displays the Top Federated result from the configured location

Social Collaboration
Contact Details – Displays details about a contact for this page or site.
Note Board – Enable users to leave short, publicly-viewable notes about this page.
Organization Browser – This Web Part displays each person in the reporting chain in an interactive view optimized for browsing organization charts.
Site Users – Use the Site Users Web Part to see a list of the site users and their online status.
Tag Cloud – Displays the most popular subjects being tagged inside your organization
User Tasks – Displays tasks that are assigned to the current user.
What’s New – This Web part shows new information from specified lists and libraries
Whereabouts – Use to display Whereabouts information.

Adding a OOB Webparts
For adding a OOB webpart to your SharePoint page you can follow the same steps mentioned in the "Adding a Webpart" section of Webpart Overiew Post.


SOME MORE ON WEBPARTS


  1. Webparts in SharePoint?
  2. Difference between .webparts and .dwp?
  3. Difference between asp.net webparts and SharePoint webparts?
  4. Webpart life cycle?
  5. Difference web parts visual web parts and traditional web part?
  6. Webpart maintenance page?
  7. Main webpart base classes?
  8. A Web Part or Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe.”
  9. How to ensure user controls (.ascx) in webpart. I mean in which method the user controls defines?
  10. Out of box web parts in SharePoint?
  11. Add Web Part inside a Master Page in SharePoint 2010?
  12. Migrate webparts that are developed in SharePoint 2007 into SharePoint 2010?
  13. Difference between user control and webpart?
  14. Connectable webparts in SharePoint?
  15. I have created one webpart and added that in a page. Because of that webpart I am not able to open my page. So I want to delete that webpart from the page. How can I delete it?
  16. Can visual webparts have more than one user controls?
  17.  Webpart deployment life cycle?
  18.  How to define custom properties  at the normal webpart and visual webpart?
  19. How to handle the visibility level of custom properties based on permission levels?
  20.  How can we do validation at the client side in wp, VWP? 
  21.  Is CQWP can fetech data across site collection means from another site collection level?
Webparts:
Web Parts are reusable components that display content on Web pages in SharePoint 2010.

A fantastic new feature in SharePoint 2010 is that you can insert a Web Part in the text of one of the Rich Text Editor zone available in the new Wiki Page. (To add, remove, or rearrange the text zones, use the "Text Layout" menu in edit mode)

When you create a team site, the home page is a wiki page. You should be able to move the web parts by Editing (Page tab > Edit) then drag/dropping the web parts to where you'd like them to go. The wiki page won't really have web part zones, but instead you can choose a "Text Layout" to arrange your page as desired. Again you can drag and drop between the layout zones.

Also, when inserting a web part, the web part is added where your cursor is. To make sure you have it in the correct location, open the web part adder first (Edit Page > Insert Tab > Web Part), then click on the page where you want it to go, and then click Add in the web part adder.

Remember points:
We can dropped webparts into anywhere inside the main content area, without having to put it into a WebPartZone (This is all happening behind-the-scenes through a dynamic zone that pushes Webparts into placeholders).


Difference Between .dwp and .webpart
  1. Dwp was the file extension used in version 2 of SharePoint and .webpart is a new extension used in version 3
  2. Version number on the xmlns attribute is different [2->2003, 3-> 2007]
  3. The main difference is that all properties passed to the web part are specified with a property element and a name attribute in version 3. Version 2 uses different element names for everything.
  1. The new important feature introduced in SharePoint on webparts is Visual webpart. It’s a combination of user control (.ascx) and assembly (.dll)
  2. Since a Visual Web Part loads a User Control (.ascx) from the SharePoint Root it needs access to run the ASP.NET method LoadControl and file system access to the ControlTemplates folder in the SharePoint Root – and this is not allowed by a Sandboxed Solution.
  3. Visual webpart cannot be deploying using sandbox solutions.

Visual sandboxed web part:

The Microsoft Visual Studio team has released the Visual Studio 2010 SharePoint Power Tools. These tools extend the existing SharePoint 2010 project templates and provide the Sandboxed Visual Web Part template that enables you to create Web Parts that can be deployed as sandboxed solutions. The use of these templates also enables designer support for designing the Web Parts.
Difference between asp.net webparts and SharePoint webparts? 

ASP.NET Web Parts: 
These Web Parts are built on top of the ASP.NET Web Part infrastructure. The ASP.NET-style Web Parts have a dependency on System.Web.dll and must inherit from the WebPart base class in the System.Web.UI.WebControls.WebParts namespace.

These Web Parts can be used in ASP.NET applications as well as in SharePoint Foundation, making them highly reusable.


SharePoint-based Web Parts:

These Web Parts have a dependency on Microsoft.SharePoint.dll and must inherit from the WebPart base class in the Microsoft.SharePoint.WebPartPages namespace.

These Web Parts can only be used in SharePoint Web sites.


Webpart life cycle:

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.

When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In 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.

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.

Webpart maintenance page
  1.  A webpart which is causing a problem in a webpart page can be removed using this page. Basically, a Webpart Maintenance page provides the list of all webparts added in a particular page and options to close or remove these webparts.
  2. Use of it: Sometimes after adding a webpart to the page, we get an error page with some message. But in this error page we won’t get any SharePoint controls (like the SiteActions, Ribbon Menu etc.,), so we cannot edit the page and remove the webpart. Then we usually go to the edit form of the page (through page library) and then click on the 'Open Web Part Page in maintenance view' link, which opens the WebPart Maintenance page to remove the webpart which is causing the problem.
  3. Shortcut to open:
  4. Instead of going to the Edit Properties form of the page, we can easily open the WebPart Maintenance page by just adding the following query string to the page URL : ?contents=1
  5. So, if your page URL is 'http://rams/pages/default.aspx' then after appending the query string it should look like ' http://rams/pages/default.aspx?contents=1'
  6. Using this approach, we can open the webpart maintenance page for all the forms pages (like /pages/forms/allitems.aspx?contents=1). But it’s not safe to remove or add any webparts in these pages, as they may affect the normal functionality.
  7. Note: This approach works on both MOSS 2007 and SPS 2010.

Difference web parts visual web parts and traditional web part?
  • The advantage of Web User Control is that you can use Visual Web Developer to design the web user control and in normal web parts all controls are created in the code itself i.e. on “CreateChildControls” method only.
  • Adding Web Part properties is cumbersome for Visual Web Parts as compared to traditional Web Parts. As you develop Web Parts, many times you will want to expose their properties so that users and administrators can supply the values for those properties.
  • Differences in Web Part Connections: This is easily achieved in a traditional Web Part because the logic code is contained in the Web Part itself.
  • Differences when Extending a Web Part: You can extend the traditional Web Part by inheriting from the WebPart class. You can then reuse the base Web Part functionality and extend it as desired. Visual Web Parts cannot be extended. Because this Web Part is a wrapper around a user control, it just contains the code to load the user control; the bulk of the Web Part code resides in the code-behind file of the user control.
  • Differences in Performance and Memory Footprint: Visual Web Parts have slightly larger memory footprints than code-only Web Parts. Visual Web Parts contain more parts (Web Part, user control) than traditional Web Parts.
  • Refer the below msdn article to get a clear idea: 

Main webpart base classes:

There are two base classes that a WebPart which is going to be consumed by SharePoint can inherit from, either the SharePoint WebPart Base class or the ASP.NET 2.0 WebPart base class. When inheriting from the SharePoint WebPart Base class your derived WebPart class will inherit from Microsoft.SharePoint.WebPartPages.WebPart. When inheriting from the ASP.NET 2.0 WebPart base class your derived WebPart class will inherit from System.Web.UI.WebControls.WebParts.WebPart. It is considered good practice to use the ASP.NET WebPart base class since the old base class is meant for backwards compatibility with previous version of SharePoint however there are four exceptions when it is better to leverage functionality from the SharePoint WebPart base class:
  1. Cross page connections
  2. Connections between Web Parts that are outside of a Web Part zone
  3. Client-side connections (Web Part Page Services Component)
  4. Data caching infrastructure.
 Note: If you create a webpart in SharePoint 2010 by default it is inheriting from Asp.Net webpart base class.

A Web Part or Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe.”
The reason for this error is if we modify default namespace into custom namespace, Visual Studio 2010 Package is not generating webpart file properly.


Make sure your webpart is added into Safe Control list in Web.config file.
Open your .webpart file in your visual studio - Make sure type element name has proper namespace & class name.

When you made changes to default name space which is being generated by  visual studio, you may not see updated namespace in type element. So make sure your webpart name space name & webpart class name placed correctly in type element's name attribute
Access http://server/_layouts/newdwp.aspx  page and make sure webpart exist. If webpart not shown in the list, still your webpart name space/classname not matches to your safe control entry in web.config file. 
Access http://server/_catalogs/wp/Forms/AllItems.aspx . By clicking on webpart opens webpart in webpart preview page.

Add Web Part inside a Master Page in SharePoint 2010?
I have added the webparts in masterpage successfully by referring the below post. Thanks, SharePoint King.
Note: we cannot add webpart zones to the master page.

Out of box webparts in SharePoint?
Below are my best references to get knowledge on out of box webparts.
  • The Content Query Web Part is a very handy tool in SharePoint Standard and SharePoint Enterprise only i.e. not available at SharePoint Foundation.
  • The CQWP is used to display the content by querying, filtering and sorting.
  • The CQWP can fetch the data based on content types.
  • By default, we can group and sort by only one field.
  • Minimum designer level permissions required.
  • CQWP is part of a bundle of features called “SharePoint Server Publishing Infrastructure”.
  • The Content Query Web part cannot fetch data across site collections. If you really need it, you can take a look at the Lightning Conductor Web Part.
  • Ref: http://sharepointlogics.com/2012/03/how-to-use-content-query-webpart-in.html
DVWP:

  • A Data View Web part is a great way to display data with filtering, grouping, and user desired formatting.
  • SharePoint Designer is required for developing DVWP.
  • DVWP can fetch data from data sources other than lists like xml files.
  • DVWP can fetch data from other site collection.
  • DVWP can merge data from more than one list.
CQWP:

  • The Content Editor Web Part (CEWP) allows you to add text, html, scripts or styles to a SharePoint page.
XSLT list Web part:

  • Introduced in SP2010.
  • In SharePoint 2010, all views in lists and libraries are XSLT list view web parts. This means that you can edit views from the browser or from SharePoint Designer 2010.
CSWP:

  • Introduced in SP 2013.
  • The Content Search Web Part (CSWP) is a Web Part that displays search results based on a search query.
Difference between user control and webpart?
Webparts are like user controls, user controls are added in code but webparts are added at runtime.
The advantage of Web User Control is that you can use Visual Web Developer to design the web user control and in normal web parts all controls are created in the code itself i.e. on “CreateChildControls” method only. 

User Control
Web Part
User controls are based on Microsoft ASP.NET, and most developers are familiar with developing user controls. This improves productivity.
In general, developers are not familiar with creating child controls by writing the code from scratch.
User controls can be used with ASP.NET -based solutions. If you decide later to convert a project containing a user control to an ASP.NET -based solution, you should be able to use the control without making any changes.
Web Parts can be used in ASP.NET -based solutions only when the solution uses Web Parts pages.
The Visual Web Developer designer provides support for designing the UI by using drag-and-drop operations that gives the control a consistent look-and-feel, which results in faster development.
The controls in Web Parts must be added by using code.
User controls must be compiled before use, which adds to the time it takes to load the control.
Web Parts are precompiled and ready for use as soon as you need them.

Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...