Error handling for SharePoint 2010 custom code

How to handle errors in SharePoint 2010 ?

Error Unhandled exception was thrown by the sandboxed code 
wrapper's Execute method in the partial trust app domain: 
An unexpected error has occurred.

When you write any custom code, so it is very important to handle an exceptions while development. For custom code, there are many ways to handle the errors in the code.

There are a lot of logging applications are available for .NET and third party tools are there to have logging code ready for implementation on your SP 2010 project for your application.

When you write any custom code for WebParts, then a web part error can cause an entire page to throw an application error in the application and WebPart is important component which should have good handling of exceptions in your application.

So we should not use Try-Catch everywhere in your code rather you can have the service layer in your application architecture.

Issues with Try-Catch-finally block approach:

Generally we use try-catch and finally block to find SharePoint items to find if the item for list, libraries and document items exists or not. Even they dont have items,we dont get any exceptions so its of no use.

When we use ClientContext.ExecuteQuery in our code then it will be executed more than once for Catch block and again in Finally block.

Hence we should use ExceptionHandlingScope so that the lines of code will look much smarter and easier to read with ExceptionHandlingScope.

How to use ExceptionHandlingScope?

ExceptionHandlingScope class ignores an exception that is raised by the server, or executes code in response to an exception that is thrown by the server.

public sealed class ExceptionHandlingScope : IFromJson

Using ExceptionHandlingScope, only one request is sent to the server. Logics in ExceptionHandlingScope are packed together and sent to the server which is executed as a whole in a single request.

Also used for reducing number of calls to the server makes the debugging and modification easier. 

So for all SharePoint Developers, ExceptionHandlingScope class is very useful for handling exceptions and errors caused in the application.

How to generate and deploy WSP (Solution Packages) in SharePoint 2010 ?

How to deploy WSP (Solution Packages) file in SharePoint 2010?

There are few assumptions before making this wsp solution deployment :

  • You have a Visual Studio 2010 installed on your machine and SharePoint project set up and ready to go.
  • The project compiles with success.
  • Are able to use Powershell to execute your quick commands.

How to Generate WSP ?

Here to follow the deployment process, follow the simple steps as follow:

  1. The first step is to build your project by right clicking on your project/solution in Visual Studio 2010 and choose “Build”.
  2. Depending on your configuration, you can build to a debug or release directory.
  3. Browse the location from your computer directory which will be located in “C:<Project Directory>bin<release or debug>“. 

wspYou can see the files – an assembly dll and your .wsp file in your location shown in the left image. So this is the WSP file which you will be required for your solution deployment in SharePoint 2010.

How to deploy a SharePoint 2010 WSP ?

Depending your approach, you can execute below commands in Power Shell in SharePoint

  • Add Solution
    Add-SPSolution c:<path><solution filename>.wsp
  • Deploy/Install Solution
    Install-SPSolution –Identity <solution file>.wsp –WebApplication http://<url> -GACDeployment
  • Update Solution
    Update-SPSolution –Identity <solution file>.wsp –LiteralPath c:<path><solution file>.wsp –GACDeployment
  • Uninstall Solution
    Uninstall-SPSolution –Identity <solution file>.wsp –WebApplication http://<url>
  • Remove Solution
    Remove-SPSolution –Identity <solution file>.wsp

You’re done!!

Verify that your assembly is the GAC (C:windowsassembly) and then go activate any features you may have had in your solution. 

Hope now you know “How to generate and deploy a SharePoint 2010 WSP ?”

How to do SharePoint 2010 Content Deployment ?

What is SharePoint Content Deployment ?

Content Deployment can be use to export (deploy) content from one site collection to another site collection.

Content deployment will take care of following contents in the source site collection -

  1. -Web pages – Deploy corresponding images styles , master pages and etc.
  2. -libraries
  3. -lists
  4. -resources

Content Deployment will not deploy the below contents-

  1. -Programs
  2. -Assemblies
  3. -Features
  4. -Configuration information (Web.config) 

You can configure the Content Deployment as below-

How to configure Content Deployment:

First, we need to Create a site collection in the Production Server.

then, go to Central Administrator –> General Application Settings–> Configure Content Deployment in the Production Server.

What is Workflow in SharePoint 2010

Workflows in SharePoint Server 2010 :

Workflow enable an enterprises to reduce the amount of unnecessary interactions between people as they perform business processes.

SharePoint workflows can be developed in SharePoint designer or Visual Studio.

SharePoint 2010 provides a set of welcome workflow improvements. 
With SharePoint 2010, Microsoft introduced the .NET Framework 3.5 SP1 (and, then, Workflow Foundation 3.5). Even though a new version of Workflow Foundation 4.0 – with its improved architecture and design is provided with the .NET Framework 4. Microsoft chose to stick with a tested and reliable product. 
All the defined steps represents a business process. The number of human interactions that occur in business processes can inhibit speed and the quality of decisions.

SharePoint 2010 workflow improvements include the following features:

–Workflows that can be associated with websites (and not the lists)
–New options in out-of-the-box workflows
–The ability to create workflows by using Visio 2010
–The ability with SharePoint Designer 2010 to create workflows that can then be used out-of-the-box.

What is Apps for SharePoint 2013 and different type associated Apps

Apps for SharePoint 2013

A new custom component called the apps for SharePoint is not available in SharePoint 2013 which can be very useful for creating new functionality and user interface components.

The SharePoint 2013 Apps infrastructure also provides many benefits for SharePoint administrators by making it easier to manage the life cycle of custom applications.

There are some features provided as below :
  • SharePoint Marketplace
  • Corporate App Catalog
  • Removing Apps
  • Apps in Multi-Tenant Farms

What is Sharepoint Designer Workflow ?

8 Steps to create Sharepoint Designer Workflow:

Follow below steps for creating sharepoint designer workflow-

  1. Create a team site using the SharePoint team site template
  2. Create two task lists, one is incomplete task list and the other completed task list. To create task list, click on site action -> Create: Add a new library list -> create a task.
  3. Start the SharePoint designer
  4. Open the site in your SharePoint designer using click on file -> open site.
  5. Go to workflows by clicking on file -> new -> SharePoint content and click ok
  6. The first is this workflow will be attached to which list. Currently we have attached the workflow to incomplete tasks list. Second we need to define the events on which the workflow should be activated. For the current scenario, we have considered two events; one when the item is created and the second when the item is updated.
  7. Now, we need to define on what condition the workflow will execute and what action should take place if the condition is true. So when a task status is completed, two actions will take place. First the task will be copied from the incomplete task list to the completed task list. Second the task is deleted from the incomplete task list. Once you click finish, you can see the workflow created in the SharePoint designer.
  8. Ok, now it’s time to see the workflow in action. So go to incomplete task list and create a task with status completed.

Exporting and Importing SharePoint 2010 Content

Exporting a Site, Library or List using Central Administration-

The SharePoint 2010 Central Administration UI allows you to export the site, library and list to the file system. Note that to import them back you need to use a PowerShell cmdlet or the STSADM tool. Central Administration does not have provision for importing it back.

Go to START -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Central Administration, on the left side click on Backup and Restore link, then in the detail pane, click on Export a Site or list link under the Granular Backup section
export import content
Exporting and Importing SharePoint content

What are the SharePoint 2010 Editions ?

SharePoint 2010 consists of following editions:

  1. SharePoint Foundation 2010 (the free version)
  2. Microsoft SharePoint Server 2010 Standard Edition
  3. Microsoft SharePoint Server 2010 Enterprise Edition

Concepts of SharePoint 2010 mainly used for:

  • Governance considerations as related to business use of SharePoint.
  • Apply best practices associated with site and site collection administration.
  • SharePoint 2010 is used to Share Information in collaboration.
  • SharePoint 2010 is used to manage a collaborative team within the organization.
  • Identify and understand how to best make use of the core functionality available in SharePoint Foundation 2010.

What is Windows Power Shell in SharePoint 2010

Windows Power Shell in SharePoint 2010:

Windows PowerShell is a new command shell editor and scripting language for windows.
It consists of all the commands on command line shell and scripting language built on .Net framework which will give you shell command line to get all the objects by command execution.
PowerShell provides the good functionality towords Administrations which is used to perform the administrative tasks on local and remote windows system effectively.


Windows PowerShell ?

Windows Power Shell in SharePoint is the most preferred tool mainly to administer, automate and quick acitvity with commands in SharePoint 2010, 2013, and Office 365.

It’s very easy and understand with is the PowerShell, its use and if you are thinking to learn Powershell in SharePoint then this is the best suitable time to handle the functionality with Powershell in SharePoint.

At the end of learning and practicing the Windows Power Shell in SharePoint 2010, you will be an expert in administering and also automating your SharePoint configuration and management in your application. Keep reading and start practicing the Windows Power Shell in SharePoint 2010.

You understand – What is Windows Power Shell in SharePoint 2010? keep reading :)

What is SharePoint Object Model in SharePoint 2010 ?

SharePoint Object Model in SharePoint 2010:

To access SharePoint items or objects, you need to retrieve that items properties as well as its methods in programming using Visual Studio 3.5. For accomplishing this, you can use SharePoint 2010 object model.
SharePoint object Model provides different types of classes for accessing various SharePoint 2010 items like Web Application, Site Collection, Sites, list, libraries and many more which are already available in SharePoint 2010.

There are two types of SharePoint Object Model in SharePoint 2010:

  1.     Client Object Model
  2.     Server Object Model

For programming of SharePoint Object Model you will need to use namespace in visual studio code.

Namespace Used for Server Object Model:

The Server Object Model classes are available under the Microsoft.SharePoint assembly namespace. 
The regular classes are available in the Microsoft.SharePoint namespace and for the administration classes which are available under the Microsoft.SharePoint.Administration namespace.

Here we are talking about the Server Object Model.

There are some main and important classes for accessing SharePoint object model items through programatically are given as follows-

Here are some classes for Server Object Model:

  • Farm -> SPFarm
  • Server->SPServer
  • Site Collection->SPSite
  • Web site ->SPWeb
  • List->SPList
  • Document Library->SPDocumentLibrary
  • Content Type -> SPContentType
  • Control->SPControl
  • User -> SPUser
  • SharePoint Exception->SPException