Month: July 2012

SharePoint 2013 various object model overview

SharePoint 2013 provides an exhaustive list of options in terms of API set,  when it comes to application development. The SharePoint 2013 platform provides the following options for developing applications around SharePoint.

  • Developing an app for SharePoint
  • Developing a Custom Web Part for a SharePoint Page
  • ASP.NET application rendered through IFrame on a SharePoint Page
  • Javascript/EcmaScript running in a Site Page
  • Silverlight application(hosted in a website or running in a mobile device) accessing SharePoint data
  • .NET Client application accessing SharePoint data
  • Windows Powershell
  • Timer job running on a SharePoint Server

The developers need not acquire any new skills for developing applications on SharePoint 2013. The developers can continue to leverage their existing skills on JavaScript, ASP.NET, Windows Powershell, Silverlight, Windows Phone, .NET Framework and REST/OData. The following table provides an overview of various development scenarios around SharePoint 2013 and the relevant object model to be used for each scenarios for development.


No Development Scenario Object Model
1 Development of custom web parts Server Object Model
2 Develop of custom application page Server Object Model
3 Development of User Control Server Object Model
4 Development of Custom Workflow Server Object Model
5 Development of Custom Timer Job Server Object Model
6 Development of Custom Event Handlers Server Object Model
7 Development of Windows Phone App to perform CRUD operations on SharePoint data Mobile Client Object Model
8 Development of Windows Phone App to implement Microsoft Push Notification Service that alerts  mobile device (for events in SharePoint) Mobile Client Object Model
9 Development o f LAMP (Linux-Apache-MySql-Php) application that performs CRUD operations on SharePoint data REST / oData end points
10 Development of iOS or Android application that performs CRUD operation on SharePoint data REST / oData end points
11 Development of ASP.NET application that performs CRUD operations on SharePoint data outside of firewall JavaScript client object model
12 Development of an HTML / JavaScript applications that performs CRUD operations on SharePoint data JavaScript client object model
13 Development of ASP.NET application that performs CRUD operations on SharePoint data inside firewall .NET Framework client object model or Silverlight Client Object Model or REST / oData endpoints
14 Development of a .NET client application that performs CRUD operations on SharePoint data .NET Framework client object model


I’d explore more on SharePoint 2013 and keep sharing my leanings in the forthcoming posts.

 Subscribe to my blog

Create custom verbs for SharePoint 2010 web parts

The web part verbs are the menus items (like Minimize, Close etc) appears when we click the Edit option in web parts. The SharePoint web part framework exposes one of the propery called WebPartVerbCollection. This is very flexible which allows us to add our own items (custom web part verbs) to the web part collection.

The whole idea is to override the getter of WebPartVerbCollection property, add custom verb items and return it back to web part framework. The following code snippet covers the same.

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

namespace WP_Verb_Sample.VisualWebPart1
    public class VisualWebPart1 : WebPart
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/WP_Verb_Sample/VisualWebPart1/WPVerbSample.ascx";

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

        public override WebPartVerbCollection Verbs
                //return base.Verbs;

                WebPartVerb Verb1 = new WebPartVerb("Verb Inovking Server Handler", 
                                              new WebPartEventHandler(CustomVerbEventHandler));
                Verb1.Text = "Verb Inovking Server";
                Verb1.Description = "This verb is used to demonstrate the server-side WP verb operation";

                WebPartVerb Verb2 = new WebPartVerb("Verb Inovking Client Script", 
                                              "Javascript:alert("Hi from Client");");
                Verb2.Text = "Verb Inovking client script";
                Verb2.Description = "This verb is used to demonstrate the client-side WP verb operation";

                WebPartVerb[] addedVerbs = new WebPartVerb[] { Verb1, Verb2 };

                return new WebPartVerbCollection(base.Verbs, addedVerbs);


        protected void CustomVerbEventHandler(object sender, WebPartEventArgs args)
            // any arbitrary operation can be performed here

The web part verbs can invoke both a client-side action and a server-side handler as well. The above sample covers both the scenarios. Once you compile and deploy this code, you’d see your custom webpart verb.


 Subscribe to my blog

Consuming a WCF Service from SharePoint 2010 web part

In this article I’d cover the steps to be followed to consume a IIS 7.5 hosted WCF service from SharePoint 2010 visual web part.


Make sure that web part project has references to the following assemblies




 Import the following namespace in the code-behind of the web part
using System.ServiceModel;
using System.Runtime.Serialization;
The next step is to generate the client proxy for the WCF service. You can use ‘Add Service Reference’ option in Visual Studio 2008/10 or leverage 
the command line utility svcutil.exe. Personally I’d prefer the svcutil.exe tool for many reasons.

svcutil /config:output.config   /out:CreditCardService.cs /tcv:Version35 /n:*,SandboxVisualWP.VisualWebPart1 http://localhost:1414/CreditCardService/ValidationService.svc

/config – specifies the name of the client configuration file to be generated

/output – specifies the name of the client proxy file (.cs file)

/tcv – specifies the .net framework version for the client proxy

/n:* – specifies the namespace for the client proxy. This is a significant factor that needs to be considered. Please make sure that the namespace of the proxy file matches with the namespace of visual web part project.


The generated client configuration file looks like the following

<?xml version="1.0" encoding="utf-8"?>
                <binding name="WSHttpBinding_IVadlidationService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
            <endpoint address=""
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IVadlidationService"
                    <dns value="localhost" />

If the web part is of type farm-solution copy the contents of this configuration file and place it inside the System.ServiceModel section of the web.config file


My generated proxy file looks like the following. If you are using visual studio 2010 to create a proxy, it will always create a client proxy .cs file targetted to .NET Framework 4.0


// <auto-generated>

//     This code was generated by a tool.

//     Runtime Version:4.0.30319.269


//     Changes to this file may cause incorrect behavior and will be lost if

//     the code is regenerated.

// </auto-generated>


namespace SandboxVisualWP.VisualWebPart1


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "")]


    public interface IVadlidationService



        string GetCountry(int value);
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "")]
    public interface IVadlidationServiceChannel : SandboxVisualWP.VisualWebPart1.IVadlidationService, System.ServiceModel.IClientChannel
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "")]
    public partial class VadlidationServiceClient : System.ServiceModel.ClientBase<SandboxVisualWP.VisualWebPart1.IVadlidationService>, 
        public VadlidationServiceClient()
        public VadlidationServiceClient(string endpointConfigurationName) : 
        public VadlidationServiceClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress)
        public VadlidationServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress)
        public VadlidationServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress)
        public string GetCountry(int value)
            return base.Channel.GetCountry(value);
6. Now add the proxy class ‘CreditCardService.cs’  to the visual web part project. 
If you try to access the client proxy on the code-behind of the Visual Web Part, the intellisense will show that class now.

For the intellisense to recognize this proxy class, the namespace of the generated proxy class has to match with the namespace of the visual web part project. If there is a mismatch in the namespace, the intellisense will not recognize this proxy class. It is always recommended to explicitly specify the namespace during the generation of client proxy using svcutil (mentioned in step 3).

Now you are all set to invoke the various service operations on the WCF service.

 Subscribe to my blog

Content Type text/xml charset=utf-8 was not supported by service

I was trying to consume a WCF service from SharePoint web part. Basically I got this error “Content Type text/xml charset=utf-8 was not supported by service. The client and server bindings may be mismatched”. After a bit of analysis, I’ve realized that the three was mismatch in the Binding type specified in the service and client configuration.  At the service-level, I had configured WSHttpBinding and at the client it was configured as BasicHttpBinding. I’ve fixed this issue by making sure that the bindings match at both the client and server.