Friday, 28 July 2017

SharePoint Interview Questions

Event Receivers……


1.         What is event receiver?
An event receiver is a piece of managed code that responds to SharePoint events when specific triggering actions occur on a SharePoint object. Triggering actions include activities such as adding, updating, deleting, moving, checking in, and checking out.
Event Receivers has taken places either synchronously or asynchronously. If the action has taken before code execution. All receivers that end with “ing” are synchronous and those which end with “ed” are asynchronous.
Synchronous Event Handlers will work before the event is completed while asynchronous event handlers will fire after the event is completed.  
Synchronous events
·         Occur before the event.
·         Block the flow of code execution until your event handler completes.
·         Provide you with the ability to cancel the events resulting in no after event (“…ed”) being fired.
Asynchronous events:
·         Occur after the event.
·         Do not block the flow of code execution in SharePoint
Note:-Event Handlers should be placed in GAC only.

2.What is the base class for List events and List Item events?

The Base class for SharePoint events is   Microsoft.SharePoint.SPEventReceiverBase. The List and List Item events inherited based on the scope of event host as below.
  List Item            : Microsoft.SharePoint.SPItemEventReceiver
  SharePoint List :  Microsoft.SharePoint.SPListEventReceiver
3. Cancel  the actions using event receiver?
SharePoint before events(synchronous) can be cancelled since it get trigged before completing the operation. Any validation can be applied as well as the event can be cancelled using event properties.
E.g
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
if(condition=true)
{
properties.Cancel=True;
}
}

4.What is the difference between event receiver and workflow?
Workflows:
·         SharePoint Workflow consist a set of task(s) which can be triggered both manually and automatically.
·         SharePoint Workflows are created in SharePoint Designer, Microsoft Visio and of course through Visual Studio.
·         The workflow is triggered once an action is completed.
·         Workflow can be exported and imported
·         Workflow can be paused
·         Workflow can send mails without attachment
·         Does not required coding knowledge to work on SPD workflows
·         Multiple forms(initiation, task edit..) can be associated as part of workflow
Event Receivers:
·         SharePoint event receiver contains custom coding/logic which can be triggered automatically based on the event host type.
·         SharePoint event receivers can be created only in Visual Studio.
·         The events can be triggered before action or after action.
·         Events cannot be exported and imported
·         Events can be cancelled(synchronous) but cannot be paused
·         Even receivers  can send mails with attachment
·         Required coding knowledge
·         No custom forms associated as part of event actions

5.  Why can’t we use SPContext in even receiver?
The event properties should be used to get the current SPContext. If we get the current context of the site in different object  like SPContext then your connection may get lose when your dispose the site context.  Use SPItemEventProperties.Site/SiteID properties to get the current context or use SPItemEventProperties.Context property.

6. Can event receiver deployed as sandbox solution?
Yes, Event receivers can be deployed as sandbox solution. But make sure that your custom code is not using RunWithElevatedPrevillege method. Sandbox solution only can access the site collection object and it cannot access other than site collection object, network resources, database
7. What are the new event receivers added in SharePoint 2010?
Event Host Type
Existing Events
New Events
Events Base Class
SPSite
SPWeb
SiteDeleting
SiteDeleted
WebDeleting
WebDeleted
WebMoving
WebMoved
WebAdding
WebProvisioned
SPWebEventReceiver
SPSite
SPWeb
ListAdding
ListAdded
ListDeleting
ListDeleted
SPListEventReceiver
SPSite
SPWeb
SPList
SPContentType
FieldAdding
FieldAdded
FieldDeleting
FieldDeleted
FieldUpdating
FieldUpdated
SPListEventReceiver
SPSite
SPWeb
SPList
EmailReceived
SPEmailEventReceiver
SPSite
SPWeb
SPList
SPContentType
WorkflowStarting
WorkflowStarted
WorkflowCompleted
WorkflowPostponed
SPWorkflowEventReceiver
SPSite
SPWeb
SPList
SPContentType
ItemAdding
ItemAdded
ItemDeleting
ItemDeleted
ItemUpdating
ItemUpdated
ItemFileConverted
ItemFileMoving
ItemFileMoved
ItemCheckingIn
ItemCheckedIn
ItemCheckingOut
ItemCheckedOut
ItemAttachmentAdding
ItemAttachmentAdded
ItemAttachmentDeleting
ItemAttachmentDeleted
SPItemEventReceiver


7. What is impersonation, and when would you use impersonation?

Impersonation can basically provide the functionality of executing something in the context of a different identity, for example assigning an account to users with anonymous access. You would use impersonation in order to access resources on behalf of the user with a different account, that normally, that wouldn’t be able to access or execute something.
What are WebPart properties, and what are some of the attributes you see when declaring WebPart properties in code?
WebPart properties are just like ASP.NET control properties, they are used to interact with and specify attributes that should be applied to a WebPart by a user. Some of the attributes you see with ASP.NET 2.0 properties are WebDescription, WebDisplayName, Category, Personalizable, and WebBrowsable. Although most of these properties come from the System.Web.UI.WebControls.WebParts class, ones like Category come out of System.ComponentModel namespace.

 If I wanted to not allow people to delete documents from a document library, how would I go about it?

You would on the ItemDeleting event set: properties.Cancel= true.

When running with SPSecurity.RunWithElevatedPrivileges (web context) what credentials are being used?

In a web context, this is the application pool identity. In a timer job and workflow, this will be the 'Windows SharePoint Timer Services' identity.
When should you dispose SPWeb and SPSite objects? And even more important, when not?
You should always dispose them if you created them yourself, but not otherwise. You should never dispose SPContext.Current.Web/Site and you should normally not dispose SPWeb if IsRootWeb is true. More tricky constructs are things along the line of SPList.ParentWeb.
Also dispose each web when iterating over SPWeb.Webs
Also dispose SPLimitedWebPartManager's SPWeb property (.web)

Timer Jobs….

How can debugging share point application and timer jobs ? with steps?
1.     build application place .dll into gac and reset iis
2.     On the Debug menu, select Attach to Process
3.     select the Show processes from all users 
check box.
4.     select W3W.exe and OSWTIMER.exe can attach
5.     refresh SharePoint site point break point.










No comments:

Post a Comment