Ads

Monday, 30 June 2014

Creating a Classic Webpart - VS 2010

Overview
Classic webparts can be created by deriving from the WebPart class. You must write the code from scratch, in the CreateChildControls method, to create the layout design of the Web Part, which can be time consuming. One of the challenges that you face when designing a Web Part that has a complex user interface (UI) is the lack of drag-and-drop support.

Creating a Classic Webpart
Following are the steps for creating a Classic Webpart.

1) Open Visual Studio and select "New Project->SharePoint->2010". The following window will open displaying all SharePoint project templates. Select "Empty SharePoint Project", give a suitable name and click "Finish".

2) The following window pops-up. Enter the suitable Site collection name for debugging purpose. You also have the option to select Farm Solution or Sandboxed Solution.  

3) Right click on Solution and select Add->New Item. 
4) Another window with SharePoint templates will open as shown in the below figure. Select "Web Part".

 5) When a webpart is added 2 main components are added. First one is the webpart "MyClassicWP" which contains all the files supporting the webpart. Second one is "Features" contains the features for deploying the webpart to the site.
(Note: We will take a closer look into features in the upcoming posts.)
6) Now we will some custom code to display a welcome text along with date and time. Add the following code in the CreateChildControls() method.
SPWeb currentWeb = SPControl.GetContextWeb(HttpContext.Current);
String currentUserName = currentWeb.CurrentUser.LoginName;
this.Controls.Add(new LiteralControl(String.Format(
"<h1>Welcome {0}!</h1>", currentUserName)));
this.Controls.Add(new LiteralControl(String.Format(
"<div>Current DateTime: {0}</div>", DateTime.Now)));

7) Select "Build-> Deploy MyVisualWebPart" to deploy the webpart to the site collection that we entered in the "SharePoint Customization Wizard" in the 2nd step.
(Note: For deploying the wepart solution to another site collection or subsite we must use the STSADM command line tool or SharePoint Management Shell. We will discuss deployment in detail in the upcoming sessions.)

8) Now open the Webpart page in "Edit mode" and click "Add a Web Part". The webpart "MyClassicWP" is now available in the webpart gallery under "Custom" group. Select the webpart and click "Add".

9) Our webpart has been created and displays the Welcome message along with date and time.

This is just small example of creating a Classic Webpart. In the next post we will create a sample visual webpart.

Thursday, 26 June 2014

Some FAQ on content type hub

Hi Readers, I have taken reference from google to collect SharePoint related interview questions from different places and write them in one place to make it easy for you all.

1. Which field types are supported?
Custom fields and external data columns are not supported(you cannot create external data columns in the content type gallery).
 
2. What happens if a web application is member of two different Content Type Hubs?  
The default Managed Metadata Service(MMS) gets the priority and will be your content type hub. However, if you customize the service application associations for the web application, you can select the appropriate MMS application proxy for the content type hub.

3. What happens if a user changing a synchronized Content Type inside the Target Site Collection?
The subscribed content types are marked 'read only' in the target site collection. Users are unable to manage/change the synchronized content types inside the target site collection. Changes to the content type should always be made in the content type hub and republihsed to push the changes to the subscribed sites.

4. What happens with content types within the sub-site structure? 
Content type subscription is a site collection level feature, so you consume the content types in the top root web and it flows down the sub-sites.

5. Are Workflows supported and if yes what are the limitations? 
 Unfortunately workflows are not supported. However, once you have your content type published to the target site collection, you can create and associate workflows to the subscribed content types in the target site.
Update: Read the following blog post on associating workflows with published content types. As always, you are able to still create list workflows in the target site collection instead of associating with the content type if required.
 
6. What happens with document templates?  
Document templates associated with the content type are also published along with the subscribed content type.
 
7. What happens with Document Set content Types?  
Yes, you can subscribe to document set content types. In this case, all the dependent content types with the document set & the document set itself will be published to the target site. However, you should have the Document set feature activated in the target site.

8. What about feature dependencies?  
Feature dependencies are not activated automatically in the target site collection. Thus, they need to be activated manually before the subscription process, else the content type publishing job will fail in the target site collection for that subscribed content type. Best example is when you subscribe to document set content types.

Ads