Monday 30 September 2013

SharePoint Basic Interview Questions Part 3


SharePoint 2010 Interview Questions With Answers
 
1. Describe the potential components for both a single server, and multiple servers, potentially several tiered farms:
Ans single-server SharePoint Server 2010 environment leverages a built-in SQL Server 2008
Express database. The problems with this environment is scalability, not being able to install the with built-in database on a domain controller, the database cannot be larger than 4 GB, and you cannot use User Profile Synchronization in a single server with built-in database installation.
Multiple tier farms would be a three-tier topology, considered one of the more efficient physical and logical layouts to supports scaling out or scaling up and provides better distribution of services across the member servers of the farm.

2. How will you use Web Parts or other solutions Created in SharePoint 2007 in SharePoint 2010?
In SharePoint 2010 the 12 hive is now replaced by 14 hive, So we will rewrite and recompile any
code that refers to files and resources in “12? hive. In addition to we must recompile custom code written for Windows SharePoint Services 3.0 and Office SharePoint Server 2007 that does not run on IIS.

3. When would you use claims, and when would you use classic?
Classic is more commonly seen in upgraded 2007 environments whereas claims are the
recommended path for new deployments.

4. What is the difference between Classic mode authentication and Claims-based authentication?
As the name suggests, classic authentication supports NT authentication types like Kerberos,
NTLM, Basic, Digest, and anonymous. Claims based authentication uses claims identities against a against a trusted identity provider.

5. What is the advantage in using Windows PowerShell over stsadm in SharePoint 2010 ?
Unlike stsadm, which accept and return text, Windows PowerShell is built on the Microsoft .NET
Framework and accepts and returns .NET Framework objects. Windows PowerShell also gives you access to the file system on the computer and enables you to access other data stores, such as the registry and the digital signature certificate stores etc..

6. What are My Sites?
Specialized SharePoint sites personalized and targeted for each user.
 

7. What are content databases?
A content database can hold all the content for one or more site collections.
 

8. What is a site?
A site in SharePoint contains Web pages and related assets such as lists, all hosted within a site
collection.

9. What is a site collection?
A site collection contains a top-level website and can contain one or more sub-sites web sites
that have the same owner and share administration settings.

10. Differentiate zones?
Different logical paths (URLs meaning) of gaining access to the same SharePoint Web application
 

11. Importance of application pools?
They provide a way for multiple sites to run on the same server but still have their own worker
processes and identity.

12.  Define Web Applications in SharePoint?
An IIS Web site created and used by SharePoint 2010. Saying an IIS virtual server is also an
acceptable answer.

13. What are Terms and Term Sets?
A term is a word or a phrase that can be associated with an item.  A term set is a collection of
related terms.

14. How many of types of Term Sets?
There are Local Term Sets and Global Term Sets, one created within the context of a site
collection and the other created outside the context of a site collection, respectively.

15. What is a sandboxed solution?
Components that are deployed to run within the sandboxed process rather than running in the
production Internet Information Services (IIS) worker process.

16. Why are sandboxed solutions used?
Primarily because they promote high layers of isolation. By default they run within a rights-
restricted, isolated process based around Code Access Security (CAS). Isolation is possible to increase with activities like running the sandboxing service on only specific SharePoint 2010 servers.

17. What is a search scope?
A search scope defines a subset of information in the search index. Users can select a search
scope when performing a search.

18. What is query logging in SharePoint 2010?
Collects information about user search queries and search results that users select on their
computers to improve the relevancy of search results and to improve query suggestions.

19. Please describe what a Service Application is in SharePoint 2010.
Service applications in SharePoint 2010 are a set of services that can possibly be shared across
Web applications. Some of these services may or may not be shared across the SharePoint 2010 farm.

Examples are mentioned below:
  • Access Services
  • Business Data Connectivity service
  • Excel Services Application
  • Managed Metadata service
  • Performance Point Service Application
  • Search service
  • Secure Store Service
  • State service
  • Usage and Health Data Collection service
  • User Profile service
  • Visio Graphics Service
  • Web Analytics service
  • Word Automation Services
  • Microsoft SharePoint Foundation Subscription Settings Service

20. What is Access Services?
Allows users to edit, update, and create linked Microsoft Access 2010 databases that can be
viewed and manipulated by using an internet browser, the Access client, or a linked HTML page.

21. What is Visio Services?
Allows users to share and view Microsoft Visio Web drawings. The service also enables data-
connected Microsoft Visio 2010 Web drawings to be refreshed and updated from various data sources.

22.  What is Performance Point Services?
Allows users to monitor and analyze a business by building dashboards, scorecards, and key
performance indicators (KPIs).

23. What is the Secure Store Service (SSS)?
A secure database for storing credentials that are associated with application IDs
 

24. What is Excel Services?
Allows sharing, securing, managing, and using Excel 2010 workbooks in a SharePoint Server
Web site or document library. Excel Services consists of the Excel Calculation Services (ECS), Microsoft Excel Web Access (EWA), and Excel Web Services (EWS) components.

25. what is the difference between SQL clustering and mirroring?
Clustering provides a failover scenario whereby one or more nodes can be swapped as active
depending on whether a node goes down. In mirroring, transactions are sent directly from aprincipal database and server to a mirror database to establish essentially a replica of the database.

26.what are the monitoring features that are present in SharePoint 2010.
Diagnostic logging captures data about the state of the system, whereas health and usage data
collection uses specific timer jobs to perform monitoring tasks, collecting information about:
  • Performance Counter Fata
  • Event Log Data
  • Timer Service Data
  • Metrics For Site Collections and Sites
  • Search Usage Data

27. Explain how connections are managed with Service Applications.
A virtual entity is used that is referred to as a proxy, due to label in PowerShell.
 
 

CAML Brief Introduction



What is CAML Query
              The CAML language has been associated with SharePoint since the first version, SharePoint 2001, and SharePoint Team Services. It is based on a defined Extensible Markup Language (XML) document that will help you perform a data manipulation task in SharePoint. It is easy to relate a list to CAML if you compare it to a database table and query. When querying a database, you could get all of the records back from the table and then find the one that you want, or you can use a Structured Query Language (SQL) query to narrow the results to just the records in which you are interested.

Example:   CAML Query Basic Example:

<Query>
   <Where>
<!--Comparison Operators here-->
<Eq>
<FieldRef Name=”insertFieldNameHere” />
<Value Type=”insertDataTypeHere”>insertValueHere</Value>
 </Eq>
</Where>
<OrderBy>
<FieldRef Name=”insertFieldNameHere” />
<FieldRef Name=”insertFieldNameHere” />
</OrderBy>
</Query>

Using CAML query in SharePoint Programming:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace CamlQuery
{
class Program
{
static void Main(string[] args)
{ "string camlQuery =
"" +
"" +
"" +
"" +
"Chen" +
"" +
"" +
"";
SPSite site = new SPSite("http://SPS123/");
SPWeb testWeb = site.AllWebs["Budget Test Site"];
SPList bdcList = testWeb.Lists["List with BDC Lookup"];
SPQuery query = new SPQuery( );
query.Query = camlQuery;
SPListItemCollection filteredItems =
bdcList.GetItems(query);
Console.WriteLine("Found {0} items in query.",
filteredItems.Count);
foreach (SPListItem item in filteredItems)
{ Console.WriteLine("Found customer: {0} {1}",
item["Customer"],
item["Customer: LastName"]);
} Console.ReadLine();
} } }"
CAML Query Comparison Operators:
Tag Name  Meaning
Contains  Contains a given text value
Eq   Equal to
Geq   Greater than or equal to
Gt   Greater than
Leq   Less than or equal to
Lt   Less than
Neq   Not equal to
DateRangesOverlap  Compares dates in recurring events to determine if they overlap
IsNotNull  Is not null
IsNull   Is null

The following code is an example to extract the FieldRef name from a list by using a console application and the Microsoft Office SharePoint Server 2007 application programming interface (API):
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace SharePointUtils
{
class Program
{
static void Main(string[] args)
{
string siteUrl = args[0];
string listName = args[1];
string viewName = args[2];
SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
SPList employeesList = web.Lists[listName];
SPQuery query = new SPQuery(employeesList.Views[viewName]);
System.Diagnostics.Debug.WriteLine(query.ViewXml);
Console.WriteLine(query.ViewXml);
Console.ReadLine();
}
}
}
Some important points about CAML Query:
->CAML query is used to perform operation on SharePoint list. ->CAML query's root element is Query.
->Where claause in CAML query is used for filter criteria. ->Order by element is used to set the elements in a specific order either by ascending or descending.
Retrieving List items from SharePoint list using CAML query.
Setting the row limit in CAML query result set.
We can set the row limit in a result set of caml query. This can be done by using SPQuery. SPQuery spqry = new SPQuery(); spqry.RowLimit = 20;
Questions about SharePoint CAML Query:
Write a caml query to get the customer details from SharePoint list called Customer.
How to fetch record from a sharepoint list using caml query, the condition is only active user record should come in result set.
What is the difference between caml query and linq in sharepoint?
Which is good caml query or linq ?
Can caml query is applicable on sharepoint document library ?.

Saturday 28 September 2013

Creating SharePoint 2010 Event Receivers in Visual Studio 2010

Overview
Microsoft Visual Studio 2010 provides a project type that enables you to build event receivers that perform actions
before or after selected events on a Microsoft SharePoint 2010 site. This example shows how to add an event to the
adding and updating actions for custom list items.
Code It
This SharePoint Visual How To describes the following steps for creating and deploying an event receiver in
Visual Studio 2010:
1. Overriding the itemAdding event and the itemUpdating event.
2. Verifying that the list to which the item is being added is the Open Position list.
3. Elevating permissions so that the code can access a secure site to retrieve approved job titles.
4. Comparing approved Job Titles with the title of a new item that is created in the Open Position list.
5. Canceling the event when the Job Title is not approved.
In this example, a secure subsite contains a list named Job Definitions that specifies allowed job titles for roles
in the organization. Along with job titles, the list also contains confidential salary information for the job title and is
therefore secured from users. In the main site, a list named Open Positions tracks vacancies in the organization.
You create two event receivers for the itemAdding and itemUpdating events that verify that the title of the open
 position matches one of the approved titles in the Job Definitions list.
Prerequisites
Before you start, create the subsite and lists that you will need.
To create the Job Definitions subsite
1. On the main site, on the Site Actions menu, click New Site.
2. In the New Site dialog box, click Blank Site.
3. On the right of the dialog box, click More Options.
4. In the Title box, type Job Definitions.
5. In the Web Site Address box, type JobDefinitions.
6. In the Permissions section, click Use Unique Permissions, and then click Create.
7. In the Visitors to this site section, select Use an existing group, and then select Team Site Owners.
8. Click OK.
To create the Job Definitions list
1. In the Job Definitions site, create a custom list named Job Definitions with the following columns:
o  Title (Default column)
o  MinSalary (Currency)
o  MaxSalary (Currency)
o  Role Type (Choice: PermanentContract)
2. Add several jobs to this list. Note the titles that you specify for each job that you create because you will
need them later.
To create the Open Positions list
·    In the parent site, create a custom list named Open Positions with the following columns:
o  Title (Default column)
o  Location (Single line of text)
Creating an Event Receiver
Next, create an Event Receiver project in Visual Studio 2010, and add code to the events receiver file.
To create a SharePoint 2010 event receiver in Visual Studio 2010
1. Start Visual Studio 2010.
2. On the File menu, click New, and then click Project.
3. In the New Project dialog box, in the Installed Templates section, expand either Visual Basic or Visual C#,
expand SharePoint, and then click 2010.
4. In the template list, click Event Receiver.
5. In the Name box, type VerifyJob.
6. Leave other fields with their default values, and click OK.
7. In the What local site do you want to use for debugging? list, select your site.
8. Select the Deploy as a farm solution option, and then click Next.
9. On the Choose Event Receiver Settings page, in the What type of event receiver do you want? list, select 
List Item Events.
10.  In the What Item should be the event source? list, select Custom List.
11.  Under Handle the following events, select the An item is being added and the An item is being updated
check boxes. Click Finish.
To modify the events receiver file
1. In the events receiver file, add the following code to the class.
VB
Public Function CheckItem(ByVal properties As SPItemEventProperties) As Boolean
Dim jobTitle As String = properties.AfterProperties("Title").ToString()
    Dim allowed As Boolean = False
    Dim jobDefWeb As SPWeb = Nothing
    Dim jobDefList As SPList
    Dim privilegedAccount As SPUser = properties.Web.AllUsers("SHAREPOINT\SYSTEM")
   Dim privilegedToken As SPUserToken = privilegedAccount.UserToken

    Try
        Using elevatedSite As New SPSite(properties.Web.Url, privilegedToken)
            Using elevatedWeb As SPWeb = elevatedSite.OpenWeb()
                jobDefWeb = elevatedWeb.Webs("JobDefinitions")
                jobDefList = jobDefWeb.Lists("Job Definitions")

                For Each item As SPListItem In jobDefList.Items
                    If item("Title").ToString() = jobTitle Then
                        allowed = True
                        Exit For
                    End If
                Next

            End Using
        End Using

        Return (allowed)

    Finally
        jobDefWeb.Dispose()
    End Try
End Function
C#
bool checkItem(SPItemEventProperties properties)
  {
      string jobTitle = properties.AfterProperties["Title"].ToString();
      bool allowed = false;
      SPWeb jobDefWeb = null;
      SPList jobDefList;
      SPUser privilegedAccount = properties.Web.AllUsers[@"SHAREPOINT\SYSTEM"];
      SPUserToken privilegedToken = privilegedAccount.UserToken;
      try
      {
          using (SPSite elevatedSite = new SPSite(properties.Web.Url, privilegedToken))
          {
              using (SPWeb elevatedWeb = elevatedSite.OpenWeb())
              {
                  jobDefWeb = elevatedWeb.Webs["JobDefinitions"];
                  jobDefList = jobDefWeb.Lists["Job Definitions"];
                  foreach (SPListItem item in jobDefList.Items)
                  {
                      if (item["Title"].ToString() == jobTitle)
                      {
                          allowed = true;
                          break;
                      }
                  }
              }
          }
          return (allowed);
      }
      finally
      {
          jobDefWeb.Dispose();
      }
  }
2. In the EventReceiver1 file, replace the ItemAdding method with the following code.
VB
Public Overrides Sub ItemAdding(properties as SPItemEventProperties)
    Try
        Dim allowed As Boolean = True

        If properties.ListTitle = "Open Positions" Then
            allowed = CheckItem(properties)
        End If

        If allowed = False Then
            properties.Status = SPEventReceiverStatus.CancelWithError
            properties.ErrorMessage = _
              "The job you have entered is not defined in the Job Definitions List"
            properties.Cancel = True
        End If

    Catch ex As Exception
        properties.Status = SPEventReceiverStatus.CancelWithError
        properties.ErrorMessage = ex.Message
        properties.Cancel = True
    End Try
End Sub

C#
public override void ItemAdding(SPItemEventProperties properties)
    {
      try
        {
            bool allowed = true;

            if (properties.ListTitle == "Open Positions")
            {
             allowed = checkItem(properties);
            }
       
               if (!allowed)
            {
               properties.Status = SPEventReceiverStatus.CancelWithError;
               properties.ErrorMessage =
                 "The job you have entered is not defined in the Job Definitions List";
               properties.Cancel = true;
            }
        }
        catch (Exception ex)
        {
            properties.Status = SPEventReceiverStatus.CancelWithError;
            properties.ErrorMessage = ex.Message;
            properties.Cancel = true;
        }
    }
3. In the EventReceiver1 file, replace the ItemUpdating method with the following code.
VB
Public Overrides Sub ItemUpdating(properties as SPItemEventProperties)
        Try
            Dim allowed As Boolean = True

            If properties.ListTitle = "Open Positions" Then
                allowed = CheckItem(properties)
            End If

            If allowed = False Then
                properties.Status = SPEventReceiverStatus.CancelWithError
                properties.ErrorMessage = _
                  "The job you have entered is not defined in the Job Definitions List"
                properties.Cancel = True
            End If

        Catch ex As Exception
            properties.Status = SPEventReceiverStatus.CancelWithError
            properties.ErrorMessage = ex.Message
            properties.Cancel = True

        End Try
End Sub
C#
public override void ItemUpdating(SPItemEventProperties properties)
    {
          
        bool allowed = true;

        if (properties.ListTitle == "Open Positions")
        {
            allowed = checkItem(properties);
        }
       
        try
        {
           
            if (!allowed)
            {
                properties.Status = SPEventReceiverStatus.CancelWithError;
                properties.ErrorMessage =
                  "The job you have entered is not defined in the Job Definitions List";
                properties.Cancel = true;
            }
        }
        catch (Exception ex)
        {
            properties.Status = SPEventReceiverStatus.CancelWithError;
            properties.ErrorMessage = ex.Message;
            properties.Cancel = true;
        }
    }
To deploy the project
1. In Solution Explorer, right-click the project, and then click Deploy.
2. In the SharePoint site, in the Open Positions list, click Add new item.
3. In the Title field, provide a title for a job description that does not exist in the Job Definitions list in the
secured subsite.
4. Click Save. You receive a message from the event receiver.
5. In the Title field, provide a title for a job description that exists in the Job Definitions list in the secured
subsite.
6. Click Save. The position is created.
Read It
·    The solution overrides the ItemAdding and ItemUpdating methods and verifies whether the list that is
being added to is the Open Positions list. If it is, a call is made to the CheckItem method, passing in the
properties that are associated with the event.
·    In the CheckItem method, the permissions are elevated to ensure successful access to the secured subsite.
The job titles that are in the approved list are compared to the job title of the properties.AfterProperties 
property associated with the event. If any title matches, the allowedBoolean variable is set to true, and the
 method returns.
·    Depending on the value of the allowed variable, the calling method either permits the event or sets the
properties.ErrorMessage property and then cancels the event using properties.cancel.