SharePoint Exclusive Interview Questions and Answers (47) - Page 2

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

47 records found.

Get 650+ Questpond's Interview videos on discount

Can you explain the broader steps for deploying/activating a feature? Contd.

Step 2 :- We need to register the compiled assembly in GAC and provide the token value in the ‘Feature.XML’ file. You need to use GACUTIL to register. You can get the token by browsing to ‘c:\Windows\Assembly’ and then viewing the properties of the assembly.
 



Step 3:- Copy the two XML file i.e. ‘Feature.xml’ and ‘ElementManisfest.xml’ in the ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\DisplayCustomPage’ directory.



Step 4:- Now we need to install the feature using STSADM.exe. So go to dos prompt à and go to ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN’ directory.
 

>cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN

To install the feature run the below command using ‘STSADM’. Please note that you need to specify the relative directory path and not the physical path of ‘Feature.xml’ file.
 


>stsadm -o installfeature -filename DisplayCustomPage\Feature.xml

To ensure that SharePoint registers about this feature run IISRESET on the machine.

Step 5:- Now click on the Site Action à Site Settings à Site Features and Activate the feature.
 



Now you can see your feature enabled in the site actions menu. If you click on the feature i.e ‘Display Custom Pages’ it will redirect you to ‘SimplePageCodeBehind.aspx’.



The other point to be noted is that the events have fired and set the title and description as described in the code.



Try to experiment and deactivate the feature and you will see the title and description changing.
 



How can we provision page template and page instances?

How can we provision page template and page instances?
 


Before we move ahead with this question let’s first define provisioning. Provisioning is a fancy name of making something available. So let’s first create a page template using the ‘Default.Master’ and the see how we can provision this page on the website.. So below is the code snippet where we can create a master page from the ‘Default.Master’.
 

<%@ Page MasterPageFile="~masterurl/default.master"%>


<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderMain">
<h3>Hi this is a Page made from Page template</h3>
</asp:Content>
 

In order to use the template we need to create an instance in the SharePoint runtime. Creating a instance of the template in the SharePoint runtime is termed as provisioning.
 



We need to use the ‘Module’ and ‘File’ tag to provision an instance of the template page. This is done in the ‘ElementManifest.XML’ file. Below is the code snippet of ‘ElementManifest.XML’ file which has the module tag with a file tag specifying what the URL page name is? This is the same template which we had shown on the top. ‘PageA.aspx’ is the instance name and ‘MyPage.aspx’ is the physical page name of the template page.

The type attribute has two values ‘Ghostable’ and ‘GhostableInLibrary’. If you want to provision a resource inside a document library then you need to specify ‘GhostableInLibrary’. If you do not want to provision a resource inside a document library then you need to specify ‘Ghostable’ value. For the current exercise we have given the value as ‘Ghostable’.

A note the path attribute has the page in the ‘MyPath’ folder.
 

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Module Path="MyPage" Url="SitePages">
<File Url="MyPage.aspx" Name="PageA.aspx" Type="Ghostable" />
</Module>
</Elements>

As said previously we also need to define the feature.xml file which has the receiver class and the element manifest pointing to the elementmanifest.xml file.
 

<Feature Id="701B7EA3-0816-4a5f-8FFE-AD15F0E5B562" Title="Provision"

Scope="Web"
Description="This features enables us to goto Custom Page"
Hidden="FALSE"
ImageUrl="menuprofile.gif"
ReceiverAssembly="ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=52bd1db23825a2e4"
ReceiverClass="ClassLibrary1.clsFeatureActivator"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ElementManifest.xml" />
</ElementManifests>
</Feature>

In the receiver class we will add menu items in the quick launch nodes. So in the activation event we will add a link which will activate this feature and in the deactivation event we will remove this feature.

So in the activation event we first need to get reference to the SpSite object using the URL.
 

SPSite ObjQuickLaunch = new SPSite("http://mum2815dz:2/sites/LearnSharePoint");

From the SpSite object we get the ‘SpWeb’ object.
 

SPWeb ObjSpWeb = ObjQuickLaunch.OpenWeb();

From the ‘SpWeb’ object we get reference to all node collection of the Quick launch menu.

SPNavigationNodeCollection QuickLauncNodes = ObjSpWeb.Navigation.QuickLaunch;

Now we create a menu of the page.

SPNavigationNode objMenuItem = new SPNavigationNode("Quest", "SitePages/PageA.aspx");

Add the menu to the quick launch node.

QuickLauncNodes.AddAsFirst(objMenuItem);

ObjSpWeb.Update();

In the deactivation event we will remove the link.
 



Now that we have done with creating the two xml files and the class which will handle the feature events , use stsadm utility to register the feature. Once you have registered it you should see the feature in the feature list display. We have named the feature as ‘Provision’ so you can see the ‘Provision’ feature.



Once you activate the feature you should see the ‘Quest’ link which points to the template instance page ‘PageA.aspx’. If you disable the feature you will not be able to browse the page instance.



Why customized pages are parsed using no-compile mode?

We had discussed previously two types of pages site pages and application pages. Site pages can be customized while application pages are standard pages like ‘settings.aspx’ which is common across sites.

When a user customizes a site page a customized version of the site page is saved in the content database. This provides lot of flexibility but it has its own disadvantages. We can customize site pages using ‘SharePoint Designer’.
 



Now let’s try to understand how a customized site page which is saved content is processed. Customized site pages are processed in six steps:-
• Step 1:- The user requests a customized page.
• Step 2:- SharePoint HTTP handler i.e. ‘SPVirtualPathProvider’ picks the request and shoots a query to the content database to fetch the page.
• Step 3:- Site page is retrieved and sent to the SharePoint handler.
• Step 4:- The site page data is given to the ASP.NET parser. Please note this ASP.NET parser is not the one which IIS uses. This is made especially for SharePoint.
• Step 5:- Parser parses and gives the output to the handler.
• Step 6:- Handler finally gives the output back to the client.
 



Below is the reason why non-compiled pages are more efficient then compiled pages.

Compiled pages Non-Compiled pages
Once the compiled ASP page DLL is loaded it gets unloaded only when the App Domain gets recycled. It can be loaded and unloaded. In this scenario the memory management is more efficient.
 


What is safe mode processing and Safe Controls?

Any customized page is parsed using safe mode processing. This parsing brings in security. Safe mode processing guarantees that there is no inline script in the customized page. In other words safe mode processing disallows in-line script because a hacker can mount attack using in-line script. If you try to run in-line script on customized page you
will get error ‘Code blocks are not allowed in this file’.

In case you still want to run in-line script in customized pages you need to specify ‘AllowServerSideScript=true’ in the ‘SafeMode’ tag section in web.config file.
 

<SharePoint>

<SafeMode ... >
<PageParserPaths>
<PageParserPath
VirtualPath="/sites/MySite/SitePages/*"
IncludeSubFolders="true"
CompilationMode="Always"
AllowServerSideScript="true" />
</PageParserPaths>
</SafeMode>
</SharePoint>

Safe controls help us define which controls the customized pages will have. Customized pages can only have controls which are defined in the web.config file in the ‘SafeControls’ tag. For instance in the below code snippet we have defined that customized pages can use controls from ‘Microsoft.SharePoint.WebControls’.

<SafeControls>

<SafeControl
Assembly="Microsoft.SharePoint"
Namespace="Microsoft.SharePoint.WebControls"
TypeName="*"
AllowRemoteDesigner="True" />
</SafeControls>

Can you explain WSS model?

In order to understand WSS model we need to first understand different types of services used by SharePoint. SharePoint uses two major services in is IIS which is a non-data service and the other is SQL Server i.e. database related services.
 



SharePoint was designed from the view point that it can be used in web farms. So lets first visualize web farms and then we will try to understand how SharePoint visualized web farms.
Below figure shows two aspects one a normal visualization of a web farm and other the SharePoint view point. In our normal view (i.e. the left hand side of the image) we can think of farms having servers and servers having the two services (i.e. IIS and DB service). When SharePoint visualizes the farm infrastructure it’s a bit different.

SharePoint visualizes the farm infrastructure in terms of database services and non-database services. So it visualizes database services attached to servers and non-database services like IIS differently.
 



Note: - We are not sure why there is a change in visualization.

So let’s visualize how the WSS object model of SharePoint is seen.

• The parent object in the SharePoint hierarchy is the SPfarm object.
• SPFarm will have collection of server objects i.e. the ‘SPServer’ objects.
• ‘SPServer’ objects further have ‘SPDatabaseServiceInstance’ object.
• ‘SPDatabaseServiceInstance’ has a ‘SPContentDatabase’ object instance.
• From the ‘SPFarm’ you can also browse to services on farm level. ‘SPFarm’ has ‘SPService’ collection.
• ‘SPService’ in turn allow us to browse through IIS application i.e. ‘SPWebApplication’.
• ‘SPWebApplication’ has site collection which in turn has site object which can be browsed using ‘SPSite’ object.
 



Now let’s understand the object hierarchy below the ‘SPSite’. ‘SPSite’ / Site belong to site collection. In other words one site collection can have many sites inside it. Site will have lists and list will have fields.



Below is the code snippet which takes the Farm object , browses through all its services , using the service object browses through all its web application and then using web application browses through all sites.
 

// Get The local farm object

SPFarm oFarm = SPFarm.Local;

// Get all the services from the farm object
foreach (SPService objService in oFarm.Services)
{
// Check if this is a WebService type of object
if (objService is SPWebService)
{
// Cast it to a WebService object
SPWebService oWebService = (SPWebService)objService ;

// Get all Webapplications from the WebApplications collection
foreach (SPWebApplication oWebApplication in oWebService.WebApplications)
{
// Loop through all the sites
foreach (SPSite oSite in oWebApplication.Sites)
{
// Get reference of the Root object
SPWeb oWebRoot = oSite.RootWeb;

// Any kind of processing

// Do not forget to dispose
oWeb.Dispose();
oSite.Dispose();
}
}
}
}

How can we use custom controls in SharePoint?

Step 1:- Create the custom control by inheriting from the ‘WebControl’ class and override the ‘RenderContents’ method with your implementation. In the below code snippet we are just writing the site title and site URL to the browser.
 

using System.Web.UI;

using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace NameSpaceCustomControl
{
public class CustomControl1 : WebControl
{
protected override void RenderContents(HtmlTextWriter output)
{
SPWeb site = SPContext.Current.Web;
output.Write("The Site title is " + site.Title);
output.Write("<br/>");
output.Write("The URL of the site is " + site.Url);
}
}
}

Step 2:- Compile the custom control class and generate the DLL from the same. Once the compiled DLL is generated, register the same in GAC.

Step 3:- Refer the custom control assembly in your ASPX page using the register attribute. Please note to specify the public key token of the GAC.
 

<%@ Register Assembly="CustomControl,Version=1.0.0.0,Culture=neutral,PublicKeyToken=4adae03f3c0d5b8e" 

Namespace="NameSpaceCustomControl" TagPrefix="CustomSitePages" %>

 


Specify the custom control with a proper unique ID.
 

<CustomSitePages:CustomControl1 ID="cc1" runat="server" />

 


Below is the complete code of the page.
 

<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" meta:progid="SharePoint.WebPartPage.Document"%>


<%@ Register Assembly="CustomControl,Version=1.0.0.0,Culture=neutral,PublicKeyToken=4adae03f3c0d5b8e"
Namespace="NameSpaceCustomControl" TagPrefix="CustomSitePages" %>

<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderMain">

<h3>Hi this is a Site Page</h3>
<CustomSitePages:CustomControl1 ID="cc1" runat="server" />

</asp:Content>


 


Now if you run the page you can see the custom control in action.
 



How can you view a detail error in SharePoint?

SharePoint does not give error in a user-friendly manner or in a confusing manner. For instance below figure shows it has shown ‘File not found; but the root cause is something different. Developers would like to get the exact function / method name in which the error has occurred.
 



There are four steps, in other words there are three changes we need to make to the config file and do IIS reset. So let’s go through the four steps to get the actual cause of the above error.
As said previously we need to change the ‘web.config’ file in three different places. You can get the ‘web.config’ file from ‘C:\Inetpub\wwwroot\wss\VirtualDirectories\80’ folder.
Step 1 :-Change callstack value from false to true in SafeMode attribute as shown below.

Change
 

<SafeMode MaxControls="200" CallStack="false" ...> 


to

<SafeMode MaxControls="200" CallStack="true" ...> 

Step2:- Change ‘customErrors’ tag mode from ‘On’ to ‘Off’.

Change

<customErrors mode="On" /> 


to

<customErrors mode="Off" /> 


Step3 :- Change ‘Debug’ from ‘false’ to ‘true’ in ‘Compilation’ attribute.

Change

<compilation batch="false" debug="false"> 


to

<compilation batch="true" debug="true">

Step 4 :- Restart the IIS.

You can now see a detail stack error which shows which method exactly has the issue. For instance in this scenario the ‘FeatureDeactivation’ event has the error.
 



The error in ‘FeatureDeactivation’ event happened because of the wrong URL specified for the ‘SPSite’. If you see the previous error it showed as ‘File not found’ , but in actual it was due to wrong URL name.



How can we display ASCX control in SharePoint pages?

Custom controls in ASP.NET provide huge level of reusability in ASP.NET. They are normally simple controls with ASCX extensions which can be reused in different ASPX pages. We will not be getting in to details of what an ASCX control is. In case you are not familiar with the basics please do read any ASP.NET basic book and we are sure it’s not a rocket science.

To load an ASCX control in SharePoint environment is a simple five step process.

Step1:- We need to create an ASCX. So below is a simple ASCX file which has a label ‘lblDisplay’. There are two functions ‘setText’ and ‘ClearText’ one which sets the label to value and the other clear the label. Both these methods ‘setText’ and ‘clearText’ are called by event click of two buttons ‘cmdSet’ and ‘cmdClear’ respectively.
 

<%@ Control Language="C#" %>

<script runat="server">
protected void SetText(object sender, EventArgs e)
{
lblDisplay.Text = "This is a user control";
}
protected void ClearText(object sender, EventArgs e)
{
lblDisplay.Text = "";
}
</script>
<asp:Button ID="cmdSet" runat="server" Text="Click Me" OnClick="SetText" />
<br/>
<asp:Button ID="cmdSetClear" runat="server" Text="Click to clear text" OnClick="ClearText" />
<br/>
<asp:Label ID="lblDisplay" runat="server" Text="" />

Step 2:- We need to refer this ASCX file in a ASPX page using the register attribute and refer the same using the ‘TagPrefix’ and ‘TagName’. Below is the code snippet in which we have highlighted the same in bold.

<%@ Assembly Name="Microsoft.SharePoint,Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>


<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>

<%@ Register TagPrefix="MyUserControlPrefix" TagName="MyUserControlName" src="~/_controltemplates/MyUserControl/MyUserControl.ascx" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
This page displays Custom Control in Action
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
<MyUserControlPrefix:MyUserControlName ID="id2" runat="server" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
We never knew custom control is so easy to display.
</asp:Content>

Below figure shows the overall view , interaction and explanation of ‘MyUserControl.ascx’ and ‘PageUsingCustomControl.aspx’.

 



Step 3:- We need to copy the ASCX control in the ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES’ directory. For this sample we have created a simple directory called as ‘MyUserControl’ and uploaded ‘MyUserControl.ascx’ in the same. If you remember we had referred the ASCX file using the virtual path sign ‘~’ with the ‘MyUserControl’ folder.
 

<%@ Register TagPrefix="MyUserControlPrefix" TagName="MyUserControlName" src="~/_controltemplates/MyUserControl/MyUserControl.ascx" %>


Step 4:- We also need to paste the ASP.NET page ‘PageUsingCustomControl.aspx’ in the layouts folder located at ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS’.

Step 5:- This is the easiest step we need to the run the ASPX page and enjoy the how user control runs under the SharePoint environment. Below is how the user controls looks. If you click the button ‘Click me’ the label is set with a text ‘This is a user control’. If you click on ‘Click to clear text’ it will just clear the values of the label.
 


Note: - If you are using behind code you need to register the behind code in to GAC and refer the same in the ASCX. In this example we have just used in-line code for simplicity.

What are WebParts and how does it interact with SharePoint?

It helps to build reusable components which can customized and personalized according to business user. We can either make our own webpart or we can reuse the existing one's from SharePoint itself.

Following WebParts are available with WSS :-

Data View Web Part: - Displays data with rich design support through Microsoft SharePoint Designer.

List View Web Part: - Helps us to display list content for any list in the SharePoint site.

Image Web Part: - Helps us to display image files.

Content Editor Web Part Use this to display static HTML content using a WYSIWYG editor or to link to a text file.

Members Web Part: - Helps us to display members of the site.

Page Viewer Web Part: - Displays web page in an Iframe.

WebPart is nothing but a simple class which inherits from System.Web.UI.WebControls.WebParts. In other words you can say WebPart is kind of a WebControl which can be deployed in a WebPartZoneControl.


WebPart manager control is like controller which maintains instances of Webpart. It adds WebParts to the WebPartZone when the ASP.NET pages get initialized.



In my QuickStart fourth series I will make a point to cover WebPart’s in more detail.
 


What are WebParts and in what ways does it vary in SharePoint environment?

It helps to build reusable components which can be customized and personalized according to business user. We can either make our own webpart or we can reuse the existing one's from SharePoint itself.


Following WebParts are available with WSS:-


Data View Web Part: - Displays data with rich design support through Microsoft SharePoint Designer.


List View Web Part: - Helps us to display list content for any list in the SharePoint site.


Image Web Part: - Helps us to display image files.


Content Editor Web Part: - Use this to display static HTML content using a WYSIWYG editor or to link to a text file.


Members Web Part: - Helps us to display members of the site.


Page Viewer Web Part: -   Displays web page in an Iframe.


WebPart is nothing but a simple class which inherits from System.Web.UI.WebControls.WebParts. In other words you can say WebPart is kind of a WebControl which can be deployed in a WebPartZoneControl.

 




WebPart manager control is like controller which maintains instances of Webpart. It adds WebParts to the WebPartZone when the ASP.NET pages get initialized.

 



Now let’s try to how ‘WebParts’ work in SharePoint environment. ‘WebPartManager’ uses the ‘SPWebPartManager’. ‘WebPartZone’ interacts with the ‘WebPartManager’ who in-turn stores a serialized instance of the ‘WebPart’ in the content database.  In other words code is stored in content database for customization.
 



 


The big difference is that the ‘WebPart’ code is stored in content database. So some of the differences as compared to normal ASP.NET is that, the code is deployed in content database and is parsed using ‘Safe Mode Parser’.


What are the different life cycle events that WebPart goes through?

 A ‘WebPart’ control goes through various events and has a typical life cycle.


OnInit: - This is the initialization event and is the first event to occur.


OnLoad: - The load event.


CreateChildControls: - When any child controls are added to a composite control this event fires.


EnsureChildControls: - This event makes sure that ‘CreateChildControls’ fires.


OnPreRender: - This fires just before the render event.


Page.PreRenderComplete :- When all controls have executed the ‘OnPreRender’ event this event fires.


Render: - Render the full control.


RenderContents: - Renders the contents of the control only.


What’s the difference between WebParts in WSS 2.0 and 3.0?

Ok, first let’s talk about a bit of history. ‘WebParts’ was born when WSS 2.0 was first introduced. In ASP.NET 2.0 framework new version of ‘WebPart’ was built which can run with out WSS. WSS 3.0 uses the ASP.NET 2.0 ‘WebPart’ framework.


So some quick points:-




  • If you are doing new development using WSS 3.0 you should use ASP.NET 2.0 ‘WebPart’ framework.



  • If you want backward  compatibility you an use ‘Microsoft.SharePoint.WebPartPages.WebPart’  class.


So the decision will  be more based on what level of back ward compatibility you are looking for.


Below sheet shows the new WebPart classes as compared to SharePoint Backward compatible class.



Can you explain the 6 steps we need to create a WebPart in SharePoint?

Ok, now that we have understood the basics of WebPart lets deploy a WebPart practically. There are overall three steps to deploy WebParts :-


Step 1:- Create the Webpart



The first step is to create the WebPart. Below is the code snippet of a webPart. So we need to reference the ‘WebParts’ ,  the custom webpart class should inherit from ‘WebPart’ class and finally we need to override the ‘CreateChildControls’ method with our custom implementation.


 



 


Step 2 :- Copy the compile DLL to the virtual directory in the BIN folder.


The second step is to copy the compiled DLL in the virtual directory of the sharepoint site.


You can get the virtual directory from the IIS from home directory tab in IIS. For instance the current website is hosted on the sharepoint 80 virtual site which is actually located at ‘C: \Inetpub\wwwroot\wss\VirtualDirectories\80’.


 



 


So now let’s browse to ‘C: \Inetpub\wwwroot\wss\VirtualDirectories\80\bin’ directory and copy the DLL in the bin folder.


 


Step 3:- Make entry of the WebPart in to web.config file.


Now that we have copied the DLL to ‘bin’ folder , we need to make a ‘SafeControl’ entry in the ‘Web.Config’ file of the virtual directory.


So now let’s browse to ‘C:\Inetpub\wwwroot\wss\VirtualDirectories\80’ , open the web.config file and add the class library name in the ‘SafeControls’  section of the web.config file. Below code snippet shows the same in a visual manner.


 



 


 Step 4:- Add it to the WebPart gallery


Now that we have added the WebPart in the ‘web.config’ file its time to make it available in the web part gallery. So click on Site settings à then click webparts à Click new button, you should see the figure shown below.


You can also see the webpart which you recently added is seen the gallery. To make it available click the check box and click populate gallery.


 



You should now see  your webpart  ( for this context it is SimpleLabelWebPart) in the WebPart gallery.


 



 


Step 5:- Add the WebPart to site pages.


Ok so now that our WebPart is available in the gallery it’s time to add this WebPart to a SharePoint page. So goto the page where you want to add this WebPart , click on the site action menu and click edit page as shown in the below figure.


 



 On the page you should see a  ‘Add a webpart’ button , click on it and it will populate with the existing web parts. Browse to your web part and click add.


 



Once done your webpart is now added to the site page. You can edit the default webpart properties by clicking on ‘Modify Shared WebPart’. For simplicity sake we have changed the title.


 



 


Step 6:- View the WebPart


You can see the changed title display when view the page normally. So with a few lines of coding you can see how we have achieved huge customization.


 



How can we implement customization and personalization in WebParts?

Personalization and customization is  all about improving individual user experience as per personal choices. Every human is different and everybody wants that the world moves as per their individual choice.  Same holds true for websites. For instance your website can have features like weather forecast, business news and sports news. As an admin you have the capability to change the look and feel of the website which gets displayed to all users. Now some individual users would like to only see news and not weather forecast. So the website should provide some kind of functionality where the users can go and personalize their choices so that website behaves according to their choice.


Now from the capability where the admin can change the look and feel is called a customization. This change is reflected to every viewer who comes to the site.  The capability that individual users can either choose to view the news with weather forecast and not is personalization.


Just cutting it short when changes made to site are shared by all users it’s called as customization.  When we make changes to some feature which is only shared and seen by individual users is termed as personalization.


 



Let’s try understanding personalization and customization in SharePoint using a small sample. Let’s make a label whose text / data can be personalized by every user, but its font size can only be customized by admin. The font size customization activity is only limited to admin and cannot personalized by every end user who logs in to the website.


 



Let’s create the label webpart which are discussing. So we will create a webpart whose label data can be personalized as per every user and the font size can only be customized by the admin.


The first thing is that we need to create a class for the webpart. Below is the code snippet of the webpart class. We have created two private properties font size and label data.
 

public class SimpleLabelCustomization : WebPart

{
private int _intFontSize;
private string _strLblData = "";

}


Second thing we need to do is define the personalization scope for both of these properties.


We want the label data changes to be personalized as per user. So we need to attribute the personalizable to personalizationscope.user. In order to display description and display name we specified the ‘WebDisplayName’ and ‘WebDescription’.
 

[Personalizable(PersonalizationScope.User),

WebBrowsable(true),
WebDisplayName("Personalize your Label data"),
WebDescription("This label is a personalized webpart")]
public string LabelData
{
get { return _strLblData; }
set {_strLblData = value; }
}


We want font size changes to view by all users so we need to attribute the "personalizable" value to "personalizationscope.Shared".
 

[Personalizable(PersonalizationScope.Shared),

WebBrowsable(true),
WebDisplayName("Customize font size for every one"),
WebDescription("This label is a customized webpart")]
public int FontSizeValue
{
get{ return _intFontSize; }
set{_intFontSize = value; }
}


Below is the complete code snippet with explanation.


 



 


So now that we are done with our webpart we need to deploy the same. You can see the previous question to understand how to deploy a webpart.


Now let’s see the fun of personalization. To personalize the page you need to click on the top right hand corner and then click personalize page. Now if you edit the webpart you will see only the label data can be changed.


This because we have given label data as user based personalization and font size as shared personalization. 


 



To customize the webpart we need to click on site action and click edit page. You can now see both the properties. The site actions menu can be restricted to administrators to have a better control on customization and personalization.


 



To see the actual action create two different login’s and change data with each user logged in. You will see that depending with what username you have logged in you will see the label data as per user personalization.


 



How can we create a custom editor for WebPart?

There are situations where you want to use your own custom WebPart editor rather than using the default WebPart editor.


Note: - In case you do not know how to deploy a WebPart we advice you to read the answer for question “Can you explain the 6 steps we need to create a WebPart in SharePoint?


To make your own custom web part editor is a four step procedure.


Step 1: - So the first the thing is to create the WebPart. We need to make a slight change i.e. ‘WebBrowsable (false)” so that it does not use the default ‘WebPart’ editor. Below is the code snippet of the same font size ‘WebPart’ which has ‘WebBrowsable’ value as false.


 



 


Step 2 : - The other thing which we need to do in the WebPart is override the ‘CreateEditorParts’ method and add our custom webpart editor. We will be seeing in the next step how we can create the web part editor. For this example we have created ‘SimpleWebPartEditor’.


 



 


Step 3: - In order to create your custom web part editor the first step we need to do is inherit from ‘EditorPart’ class. Currently we have created a custom web part editor class called as ‘SimpleLabelWebPart’. In this custom class we have create two labels and two text boxes. The two textboxes will take font size and label value while the labels will display description for those text boxes. In other words we have defined our UI which take inputs which can customize our web part.


 



 


Step 4: - Two activities takes place in general one is when we the user gives customization values which customizes the web part and the other when we need to synchronize the customization values with web part.


 



 


The web part customization values are stored in content database according to user logged in.  So when customization data is provided for a web part through our custom web part editor we need to override the ‘ApplyChanges’ method and push the customization data to the web part object. So in other words the data is pushed from the web part editor to the content database on per user basis.


 



Now comes the second aspect where we need to synch the web part data from content database with the web part itself. For this we need to override the ‘syncchanges’ method and push the data from the web part object in to the web part editor user interface.


Ok , now if you edit your web part you can see how the custom editor looks like.


 



What are List and Content Types in SharePoint?

SharePoint is all about data and collaboration of the data between different types of users. When we talk about data it varies from user to user and different types of meta-data. For instance below we have four kinds of user’s project manager, accountant, security personnel and HR.



All these four users have different kind of data formats. For instance the accountant needs to save data with different data types and fields  like voucher number( 20 character string) , voucher date (MM/DD/YYYY), debit (Boolean true) , credit ( Boolean false) and amount ( Double). The security needs In-time, out-time, items carried and biometrics data.


In order to bring a flexible collaborative data model which can be further extended SharePoint brought in something called as List and Content Types. Data was visualized in terms of List data as shown below. With this approach you can add more fields and content type on a need basis.

 


.



The best part about organizing data in list is the amount of flexibility and extensibility we can bring in. Some of the flexibility a list type of approach brings in are give below :-



Different views of the list


For instance an employee list can view employee wise or date wise.




Create content from external list storage


You can take a excel and instruct SharePoint to create a list of that type.


Which are the various ready made list types that SharePoint provides currently?

There are approximately thirteen different ready made list types, below mentioned are some of the most used ones.


Document library


Used for collaborating on documents with support for versioning, check-in and check-out, and workflow. Includes support for deep integration with Microsoft Office.



Form library


Used to store XML documents and forms for use with Microsoft Office InfoPath.



Wiki page library


Used for collaborative Web pages based on wiki pages, which are dynamically generated and collaboratively edited Web pages.



Picture library


A specialized document library enhanced for use with pictures. Includes support for slide shows, thumbnails, and simple editing through Microsoft Office Picture Manager.



Announcements


Used for simple sharing of timely news with support for expiration.



Contacts


A list for tracking people and contact information, with support for integration into Microsoft Office Outlook and other WSS-compatible contacts applications.



Discussions


A simple list for threaded discussions with support for approval and managing discussion threads.



Links


A list for managing hyperlinks.



Calendar


A list for tracking upcoming events and deadlines. Includes support for integration and synchronization with Office Outlook.



Tasks


A list of activity-based items that can integrate with workflow.



Project tasks


An enhanced tasks list with support for Gannt chart rendering and integration with Microsoft Office Project.



Issue tracking


A list for tracking issues and resolution, with support for prioritization.



Custom list

An empty list definition for extending with custom columns, or created using Microsoft Office Excel spreadsheets
SharePoint is about centralizing documents, how similar is to the windows folder?

As discussed in the previous questions SharePoint is all about centralizing documents.  Consider the below company example where the CEO’s computer, accountants computer, sales persons computer and the customer personal pc are storing the documents in their own personal folders. The way they send documents to each other again varies from person to person.



SharePoint centralized everything in central server. So with this approach we do not have different copies of document scattered in personnel PC. The most important point is the backups  and versioning can now be managed through the central server.


 



Consider the below figure which shows a simple folder with ‘courses’ as the top folder which has later has ‘networking’ and ‘programming’ folder. The ‘programming’ folder has ‘dotnet’ and ‘java’ folder which has a word document ‘SharePointFoBeginners.doc’.



Below is a just a zoomed picture of the folder structure we see above.



So if we want to implement the same in sharepoint


Step 1:- Click on the right side ‘Site actions’ menu and click on ‘Site Settings’.



Step 2: - You will be shown lot of option , click on ‘Site libraries and lists’ and then click on ‘Create Content’



Step 3: - You will then be popped up to create a page. We will select ‘Basic page’ for our current situation.



Step 4: - Give a page name and click on ‘Create a new document library’. The document library helps us to provide the necessary folder structure and document centralization.



Step 5: - We need to specify a name for the document library. We will specify the name as ‘Courses’ because that forms the folder name for the top folder.



Step 6: - Once you click on create you will see the courses directory at the right hand side of the quick launch menu.



Step 7: - So we have repeated step 6 and created our folder hierarchy. Now we can upload document using the upload document as shown in the figure below.



Once document is uploaded you can see the document with folder structure as shown below. Below folder structure represents exactly your windows folder structure.



In case you want to have a windows explorer look and feel. Click on action and click on open with windows explorer.



You can see the exact windows folder look and feel of your sharepoint documents.



Can we add custom fields to our document library documents?

Organizations normally have 1000’s of documents and at one point of time it becomes difficult to search and organize these documents. If you see in our previous example where we had created a document library sharepoint has only given four fields. Now if you want to add a new field called as department and with this we can filter out which document belongs to which department.



To add a custom column click on settings and click on create column as shown in the below figure.



You will then be popped to specify a name for the custom column. For the current scenario we have names it as ‘DepartMent’.



Once you click ok  you can see the newly added custom column.



If you want specify data in the custom column click on the document and click edit properties menu as shown in the figure below.



You can now specify the department name.




You can now use the custom column for search and applying filters.


What are content types in SharePoint?

Content types are extensions to custom types. Content types bring in central control and consistency on custom data type. For instance in the previous example we had added custom type as ‘Department’ now someone can add the custom field as ‘Dept’. In other words this can bring in inconsistency and we will not be able to query and filter data in a consistence manner. So in other words we can define a content type and then apply this content type across documents. In other words we can really drive organization level policies using content types.


To create a content type click on site action – site settings – from galleries section click site content types  and you will be shown a list of existing content types.


To create a new content type click create hyperlink from the same screen which is showing list of content types.


You will thrown up a screen where you need to specify the name of your content type the parent content type and group for the same.



Once the content type is created you can add new columns using the link ‘Add from new site column’. Our custom type inherited from document content types so it had two properties i.e. name and title. We had also added ‘DepartMentName’ as the custom column in the content type.



You can add new columns using the ‘Add from new site column’. We had added the ‘departmentname’ custom field for the current instance. Below figure shows different options and data type  for custom columns which are added.




Ok, now it’s time to apply this content type to our document. Click on the settings menu and then click on ‘Document library settings’.



You will be popped up with the details of the content type. Click on ‘Add from existing site content types’ and select the custom content type we have just created i.e. ‘MyContentTypeForDocuments’.



You can now select the content type for your document library.



You can see how our custom content type is seen when we try to upload the new document.



If you edit the properties you can see the ‘departmentname’ custom column in your content type.



More SHAREPOINT Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories