Wednesday, September 14, 2011

Code to retrieve all the list item detail

using System;
using System.Linq;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
class RetrieveListItemsInclude
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><RowLimit>100</RowLimit></View>";

ListItemCollection collListItem = oList.GetItems(camlQuery);

clientContext.Load(collListItem,
items => items.Include(
item => item.Id,
item => item.DisplayName,
item => item.HasUniqueRoleAssignments));

clientContext.ExecuteQuery();

foreach (ListItem oListItem in collListItem)
{
Console.WriteLine("ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",
oListItem.Id, oListItem.DisplayName, oListItem.HasUniqueRoleAssignments);
}Console.ReadLine();
}
}
}
 
source code from here

Monday, September 5, 2011

my first client object testing with the windows form :)

follow the step here : http://www.sharepointkings.com/2011/07/client-object-model-part-1.html
please remember to add the  Microsoft.Sharepoint.Client and Microsoft.Sharepoint.Client.Runtime to References.
*my small step over the cilent object model over sp2010
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint.Client;

namespace SP2010
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        public Form1()
        {
            InitializeComponent(); //not sure this is for what Smile with tongue out
        }

      public void LoadData()
        {
            string webUrl = "http://xxxxx/sites/content/support"; //replace this with your site URL
            ClientContext context = new ClientContext(webUrl);
            Web web = context.Web;
            context.Load(web);

            context.ExecuteQuery();
            this.label1.Text = web.Title + " " + web.Description;
            this.label2.Text = webUrl;
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
              LoadData();
        }
    }
}