Shalvin Interests

Tuesday, August 28, 2012

SharePoint Client Object Model


SharePoint Client Object Model is a set of libraries and classes with which you can consume SharePoint data through a specific object model, which can be considered a subset of the SharePoint Object Model.

The client object model exposes a subset of the API that the server object model does, mainly focused on the Site-Collection level and lower.

The design of the client object model is to batch interaction with SharePoint to minimize the number of
round trips that it takes to interact with SharePoint services for common actions.


Multiple platform support :
  Managed Client
  Silverlight
  ECMA


The Client Object Model uses a client runtime proxy that communicates with a Windows Communication Foundation (WCF) service. The service is located at /_vti_bin/client.svc. 
To communicate, the client proxy sends batched XML commands and the WCF services respond with a result formatted using JavaScript Object Notation (JSON).
Because all commands are batched together and the JSON notation is a compact form, the Client Object Model bandwidth use is kept to a minimum.


Assembly Requirements

1.  Managed Client Object Model
  Microsoft.SharePoint.Client.dll
  Microsoft.SharePoint.Client.Runtime.dll
These files are located in the \Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI folder.


2.  Silverlight Client Object Model
Microsoft.SharePoint.Client.Silverlight.dll
Microsoft.SharePoint.Client.Silverlight.Runtime.dll
These files are located in \Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\ClientBin

The reason for these .dlls being installed in a different location is due to how Silverlight works—
these .dlls are deployed to the same folder that some of the Silverlight building blocks are located in,
which makes it easier to access them from Silverlight.

3. ECMAScript Client Object Model
  A set of .js files
   SP.js
   SP.Core.js
   SP.Ribbon.js
   SP.Runtime.js

JavaScript files that are located in the \Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS folder

  These .js files are automatically downloaded to the browser when a use browses to SharePoint page.

There are also assemblies for working with REST/OData end points and Windows Phone.



Managed Client Object Model


using Microsoft.SharePoint.Client;

private void Form1_Load(object sender, 

EventArgs e)
{
    ClientContext ctx = new ClientContext

("http://shalvin");
    Site site = ctx.Site;
    ctx.Load(site);

    Web wb = site.RootWeb;

    ctx.Load(wb);

    ctx.ExecuteQuery();

    listBox1.Items.Add(ctx.Url);
    listBox1.Items.Add(site.Url);
}

Saturday, August 18, 2012

Replacing existing button with new Button in SharePoint 2010 with Custom Action

<CustomAction Id="Ribbon.Documents.New.NewFolder.ReplaceButton"
     Location="CommandUI.Ribbon"
     RegistrationId="101"
     RegistrationType="List"
     Title="Replace Ribbon Button">
    
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Documents.New.NewFolder">
          <Button Id="Ribbon.Documents.New.NewFolder.ReplacementButton"
            Command="MyNewButtonCommand"
            Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png?vk=4536" Image16by16Top="-240" Image16by16Left="-80"
            Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png?vk=4536" Image32by32Top="-352" Image32by32Left="-448"
            ToolTipTitle="Create a New Folder"
            ToolTipDescription="Replaced by XML Custom Action"
            LabelText="Shalvin New Folder"
            TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="MyNewButtonCommand"
          CommandAction="javascript:alert('New Folder Replaced by Shalvin');" />
      </CommandUIHandlers>
    </CommandUIExtension>
    
  </CustomAction>

Notification in SharePoint 2010

<CustomAction
  Id="NotificationDemo"
  RegistrationType="List"
  RegistrationId="101"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.New.Controls._children">
          <Button
           Id="Ribbon.Documents.New.Controls.NotificationDemo"
           Alt="Notification Button"
           Sequence="30"
           Image32by32="/_layouts/images/PPEOPLE.GIF"
           Command="NotificationDemo"
           LabelText="Notification Demo"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="NotificationDemo"
         CommandAction="javascript:SP.UI.Notify.addNotification('Hello from Shalvin', false);"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Friday, August 17, 2012

Dialog Framework With SharePoint 2010

 <CustomAction
  Id="DialogDemo"
  RegistrationType="List"
  RegistrationId="101"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.New.Controls._children">
          <Button
           Id="Ribbon.Documents.New.Controls.Demo_Dialog"
           Alt="Dialog Ribbon Button"
           Sequence="30"
           Image32by32="/_layouts/images/PPEOPLE.GIF"
           Command="Demo_Dialog"
           LabelText="Dialog Demo"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="Demo_Dialog"
         CommandAction="javascript:
             var options = SP.UI.$create_DialogOptions();
             options.url = 'http://shalvin/Shalvin/Lists/Contacts/AllItems.aspx';
             options.width = 800;
             options.height = 600;
             SP.UI.ModalDialog.showModalDialog(options);"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Adding Menu Item to General Settings in List Setting Section of SharePoint 2010

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Location ="Microsoft.SharePoint.ListEdit"
    GroupId="GeneralSettings"
    Title="ShalvinAction">
    <UrlAction Url="javascript:alert('Adding item to General Settings of List {SiteUrl}')"/>
  </CustomAction>
  
</Elements>


Custom Action for Adding a Menu to Site Actions in SharePoint 2010

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
   Location ="Microsoft.SharePoint.StandardMenu"
   GroupId ="SiteActions"
   Title ="ShalvinAction">
    <UrlAction Url="javascript:alert('Hello from Shalvin {SiteUrl}');" />
  </CustomAction>