SharePoint Interview Questions and Answers

Hi All, In this blog, I have collected few SharePoint 2010 interview Questions and Answers. 

Q. Explain Below code

 using (SPSite site = new SPSite(SPContext.Current.Web.Url)) // Gets the absolute url of the website
         
using (SPWeb web = site.RootWeb) //  Gets the root website of site collection

using (SPWeb web = site.OpenWeb())// OpenWeb accepts either GUID of sites or site URL if a parameter is blank means returns the site associated with the current URL

SPWeb - Represents SharePoint service websites

SPSite -  Represents a collection of sites in a web application.

SPWebApplication - Represents and IIS web application.

SPWebCollection - Represents a collection of SPWeb object.

SPWebTemplate - Represents a site definition or site template that is used to create SharePoint sites.

SPList - Represents a list on SharePoint Site.

SPListCollection - Represents a collection of SPList object.

SPListItem - Represents a list item or row.

SPListItemCollection - Represents a collection of SPListItem object

Base class for Timer Job - SPJobDefinition
Base class for Event Receiver - SPItemEventReceiver

Q. Write basic code to interact with SharePoint List.
Server Object Model:

   using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
SPList list= web.Lists["MyList"]; 
SPListItemCollection items= list.GetItems(); 
web.AllowUnsafeUpdates = true; 
foreach (SPListItem item in items) 
    {      
item["Title"] = "New Title";      item.Update(); 
    } 
web.AllowUnsafeUpdates = false; 
               }
       }

Client Object Model:

            ClientContext context1 = new ClientContext(Constants.SITE_URL);
            context1.AuthenticationMode = ClientAuthenticationMode.Anonymous;

            List list1 = context1.Web.Lists.GetByTitle("ListName");

            CamlQuery query1 = new CamlQuery();

            query1.ViewXml = @"<Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";


            Microsoft.SharePoint.Client.ListItemCollection listCollection1 = list1.GetItems(query1);

            context1.Load(listCollection1);
            context1.ExecuteQuery();
           
            DataTable dTable1 = new DataTable();
            dTable1.Columns.Add("Title");

    for (int iCntr1 = 0; iCntr1 < listCollection1.Count; iCntr1++)

            {
                dTable1.Rows.Add(dTable1.NewRow());          

                if (listCollection1[iCntr1]["Title"] != null)

                {
dTable1.Rows[dTable1.Rows.Count - 1]["Title"] = listCollection1[iCntr1]["Title"].ToString();

                }

   }


Q. Page Parser Path in SharePoint
There is a limitation in SharePoint, script with runat server code not allowed in Application Pages.
By adding below piece of code it can be done.

<PageParserPath VirtualPath="/myFiles/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
 </PageParserPaths>  

Now you may add below code to your page:


<script runat="server">
protected void Page_Load(Object sender, EventArgs e)
{
    Response.Write("Server side code");
}

</script>

Q. Allow unsafe update vs run with elevated privileges

Allow unsafe update is set to true when we are updating the content database to avoid external injections.

RWEP - It executes method with full rights even if the user does not otherwise have full control.

SPSecurity.RunWithElevatedPrivileges(delegate() 
{     using (SPSite site = new SPSite(web.Site.ID))     
{     // implementation details omitted    
 } }); 

Q. Safe Control in SharePoint

In sharepoint development environment a developer can add aspx file which may contain affect sharepoint environment, i.e. there might be a security risk.
To reduce the rist SharePoint allows to add safe control tag in web.config file to avoid script injection -
 <SafeControls>        
<SafeControl Assembly="[Assembly Name]" Namespace="[Namespace]" TypeName="*" Safe="True" />     
 </SafeControls> 

Safe control contains assembly name, namespace name

Q. Timer Job in SharePoint
It is a job in SharePoint that runs in background on a specified periodic basis.

public override void Execute(Guid targetInstanceId)

Execute is a override method which is responsible for executing timer job.

For more visit this link:


http://www.sharepointcafe.net/2015/06/timer-job-in-sharepoint-2010-how-to.html


Q.Throttling and Indexing in SharePoint

List in SharePoint is similar to SQL table, indexing on List improve the performance.
A SharePoint list allows 20 indices. Not all column type can be indexed.
Throttling is a process which set the limit of an item that will be accessed in a single request. Default limit is 5000.

For more see this link

http://www.sharepointcafe.net/2015/07/throttling-and-indexing-in-sharepoint.html

List threshold can be overridden by using below property



SPList.EnableThrottling
for more visit this link:
http://www.sharepointcafe.net/2015/07/throttling-and-indexing-in-sharepoint.html

Q. Create Child control in SharePoint
 private const string _ascxPath = @"~/_CONTROLTEMPLATES/MyProject.WebParts/MyVisualWebPart1/MyVisualWebPart1UserControl.ascx";

        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);

        }

It does most of the rendering work related to a control such as a label control, text box control etc.
LoadControl(usercontrolpath) is a method which loads web controls as per specified path.

Q. Web part properties using C# code

Below code is to set web part properties like width, chrome type, back color

protected override void CreateChildControls()       {
            Control control = Page.LoadControl(_ascxPath);
            ChromeType = PartChromeType.None;
            BackColor = Color.Red;
           Title = "This is a test title";
            this.ScrollBars = System.Web.UI.WebControls.ScrollBars.Both;
            this.Width = 500;
           Controls.Add(control);

        }

Q. What is GAC?
GAC stands for Global Assembly Cache

Q. Audience Targeting in SharePoint
It is a way to display list, library items to specific groups of people. Go to list or library setting ->General Settings -> Audience targeting settings
Enable Audio targeting and click on ok.

Now go to list or library select any item, click on the arrow and select edit properties.
You will now see an option for Audience Targeting.

Q. What is view in SharePoint?
A view is the way to choose what data you want to present over webpage. 
There are:
Standard View
Calendar View
DataSheet View
Gantt View
Custom View (In SharePoint Designer)

Q. Create a different view for folder inside a document library


Q. Document Set in SharePoint
Provides the content types required for creating and using document sets. Create a document set when you want to manage multiple documents as a single work product.

Q. ULS Log in SharePoint
ULS stands for Unified Logging Service
ULS helps a developer to find bugs without debugging an application.

try
{
//code
}
catch(Exception ex)             {                
   SPDiagnosticsService spDiag = SPDiagnosticsService.Local;                
  spDiag.WriteTrace(0,new SPDiagnosticsCategory("My ULS Log", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "ULS log error:  {0}",                                                         new object[] { ex.Message });                } 

ULS log viewer is a tool which presents log details in a readable format.

Q. SPSiteDataQuery in SharePoint
It is used to get data from multiple lists, and those lists could be on the same site or in multiple sites.
CrossListQueryInfo is an another way to do this but internally it uses SPSiteDataQuery .

In SPSiteDataquery there are 2 scopes that can be defined.

<Webs Scope="Recursive" /> - Current website and all sub sites

<Webs Scope="SiteCollection" /> - All websites that are in current site collection

Q. Permission levels in SharePoint.

Full Control - Has Full control
Design - View, add, update, delete, approve
Contribute - view, add, update and delete items
Read - view pages and list items and download documents

Limited Access - Can view specific lists, document libraries, list items, folders or document on given permission

Q. Application Pages vs Site Pages
Application Pages stored in hive folder.
Site Pages stored in content database.

Application Pages support code behind.
Site Pages do not allow code behind.

Q. Data View Web Part
It is a way to display data with filtering. grouping.  Data View web part was available in SharePoint 2007 and also available in 2010.
SharePoint 2010 also have XSLT List view web part.

XSLT Listview web part - It is a web part that can be modified in SharePoint designer using XSLT code.

Q. ONET.xml file
It is the core of site definition. It is located under hive folder.

Q. What are master pages available in SharePoint?
v4.master - Default team site master page.

default.master - This is the default master page for SharePoint 2007 look and feel.

minimal.master - Generally used by search centers.

simple.master - Used by SharePoint 2010 general pages like login page. error page, signout page etc.

Q. What is a Term?
A term is a keyword or phrase that can be associated with an item. A term set is a collection of related terms.

Q. Access Denied by Business Data Connectivity - Error in External List
Go to Central Admin-> Manage Service Application -> Click on Business connectivity service->
Select your External Content Type Name and click on Set Object Permission from top ribbon.

Type account name, then Add and select operation that you want to allow for this user.

Refer Below Screen -

SharePoint 2010 Interview question and answer

Q. Feature and Scope of feature available in SharePoint:
A feature is a set of code or functionality that can be activated or de-activated at various level to perform some change in SharePoint site.
Farm - It affects all web application available in a farm.
Web Application- It affects a complete web application.
Site- It affects a single site collection.
Web - It affects a single site

Q. Event Receiver
Event Handler and Receiver

There are 2 types of Events Before and After.
Generally known as Synchronous and Asynchronous events.

Event Receiver Base Class:

SPItemEventReceiver
SPListEventReceiver
SPEmailEventReceiver
SPWebEventReceiver
SPWorkflowEventReceiver


Event handler gets registered in Elements.xml file. It includes Class name, assembly name, List template id.

If any method removed/added in receiver class same will reflect in Elements.xml file.

SPItemEventProperties


properties.AfterProperties["Title"].ToString();


properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;



properties.RedirectUrl = "_layouts/EventRcvrApp/Error.aspx?msg=Item+Cannpt+be+deleted";


Q. Application Page vs Site Page vs Custom ASPX Page
Application Page
Site Page
Custom Page
Support Code behind
Do not support code behind
Can have code behind, but code behind file will not be deployed
They inherit from application.master
They inherit custom look of the site
Need to specify the URL of the custom master page
Stored in layout folder  available in hive folder
Stored in content database
Deployed in layout folder
So that's all for SharePoint 2010 interview questions and answers.

If you have more questions related to SharePoint 2010 interview, please put the same in the comment section.

Comments

Popular