Thursday, October 20, 2016

Get By Search using Client Object Model


"Client" in the namespace.  For example, in the server object model you have:
Microsoft.SharePoint.SPSite
Microsoft.SharePoint.SPWeb
Microsoft.SharePoint.SPList

In the client object model you have:
Microsoft.SharePoint.Client.Site
Microsoft.SharePoint.Client.Web
Microsoft.SharePoint.Client.List


NameSpace:


Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll


Example Code:

ClientContext context = new ClientContext("http://peakfinders.com");
List list = context.Web.Lists.GetByTitle("yourlistname");
CamlQuery query = new CamlQuery();
query.ViewXml = @"<View>
    <Query>
        <Where>
        <Eq>
            <FieldRef Name='Status'/>
            <Value Type='Text'>Pending</Value>
        </Eq>
        </Where>
    </Query>
    </View>";

ListItemCollection listItems = list.GetItems(query);
context.Load(listItems, items => items.Include(
                                                item => item["Name"],
                                                item => item["Designation"],
                                                item => item["Status"]
                                                ));
context.ExecuteQuery();


Get By Row Limit using Client Object Model


“Client” in the namespace.  For example, in the server object model you have:

  • Microsoft.SharePoint.SPSite
  • Microsoft.SharePoint.SPWeb
  • Microsoft.SharePoint.SPList

In the client object model you have:

  • Microsoft.SharePoint.Client.Site
  • Microsoft.SharePoint.Client.Web
  • Microsoft.SharePoint.Client.List


NameSpace:


Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll


Example Code:

ClientContext context = new ClientContext("http://peakfinders.com");
List list = context.Web.Lists.GetByTitle("yourlistname");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View><RowLimit>3</RowLimit></View>";

ListItemCollection listItems = list.GetItems(query);

context.Load(listItems);
context.ExecuteQuery();
context.ExecuteQuery();

Update List Items Client Object Model


“Client” in the namespace.  For example, in the server object model you have:
·         Microsoft.SharePoint.SPSite
·         Microsoft.SharePoint.SPWeb
·         Microsoft.SharePoint.SPList
In the client object model you have:
·         Microsoft.SharePoint.Client.Site
·         Microsoft.SharePoint.Client.Web
     ·         Microsoft.SharePoint.Client.List

NameSpace:


Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll


Example Code:

ClientContext context = new ClientContext("http://peakfinders.com");
List list = context.Web.Lists.GetByTitle("yourlistname");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection items = list.GetItems(query);

context.Load(items);

context.ExecuteQuery();

foreach(ListItem item in items)
    if ((item.Id % 2) == 0)
    {
        item["Title"] += "**";
        item.Update();
    }

context.ExecuteQuery();

Get List Items Client Object Model

“Client” in the namespace.  For example, in the server object model you have:
·         Microsoft.SharePoint.SPSite
·         Microsoft.SharePoint.SPWeb
·         Microsoft.SharePoint.SPList
In the client object model you have:
·         Microsoft.SharePoint.Client.Site
·         Microsoft.SharePoint.Client.Web
     ·         Microsoft.SharePoint.Client.List

NameSpace:


Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll


Example Code:

ClientContext context = new ClientContext("http://peakfinders.com");
List list = context.Web.Lists.GetByTitle("yourlistname");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection items = list.GetItems(query);

context.Load(list);
context.Load(items);

context.ExecuteQuery();

Tuesday, October 18, 2016

Custom ribbon button action always disabled when command is defined

The issue is that the feature is not enabled that allows the layouts.

To fix the issue go to Site Actions -> Site Settings in the upper right corner.

Under "Site Collection Administration" click on "Site Collection Features".

Look for "SharePoint Server Publishing Infrastructure" and activate it. It might take a moment to load.

Next return to "Site Settings" and click on "Manage Site Features"

Look for "SharePoint Server Publishing" and activate it. It might take a moment to load.