Technical Questions Technical questions on Kentico CMS Connector for Microsoft SharePoint.
Kentico CMS Connector for Microsoft SharePoint > Technical Questions > SharePoint Client Object Model View modes: 
User avatar
Member
Member
kpaxton-gpworldwide - 1/18/2011 2:32:26 PM
   
SharePoint Client Object Model
This isnt necessarily about the SharePoint connector but I was figuring this would be the best place.

I'm trying to modify the BizForm web part using the SharePoint Client OM to be able to create a BizForm and have it submit directly to a SharePoint list.

Right now for testing I'm just trying to pull back list items and i'm having some difficulty. Has anyone else here tried to use the SP Client OM to connect and retrieve list items?

Here is my code.

//SP.ClientContext context = new SP.ClientContext(SharePointSiteUrl);
//SP.List oList = context.Web.Lists.GetByTitle(SPList);
//context.Load(oList);
//SP.CamlQuery camlQuery = new SP.CamlQuery();

//SP.ListItemCollection collListItem = oList.GetItems(camlQuery);

//context.Load(collListItem);

//context.ExecuteQuery();


//litResponse.Text = "List Name: " + lst.Title + "<br/>";
//litResponse.Text += "Item Count: " + oList.ItemCount.ToString() + "<br/>";
//litResponse.Text += "Items: ";
//foreach (SP.ListItem item in collListItem)
//{
// litResponse.Text += "Title: " + item.FieldValues["Title"].ToString() + "<br/>";
//}
//for (var i = 0; i < oList.ItemCount; i++)
//{
// litResponse.Text += "Title: " + collListItem["Title"].ToString() + "<br/>";
//}
//context.Dispose();


I've got it all commented out right now just to test some other things. Any help would be greatly appreciated.

User avatar
Member
Member
kpaxton-gpworldwide - 1/19/2011 3:21:17 PM
   
RE:SharePoint Client Object Model
I figured it out.
By grabbing the credentials that were set in the SharePoint Settings in Site Manager I was able to pass those credentials to the SharePoint instance. I guess my default user wasn't authenticating to SharePoint.


using(SP.ClientContext context = new SP.ClientContext(SharePointSiteUrl))
{
ICredentials creds = SharePointFunctions.GetSharePointCredetials();
context.Credentials = creds;
SP.List oList = context.Web.Lists.GetByTitle(SPList);
context.Load(oList);
SP.CamlQuery camlQuery = new SP.CamlQuery();

SP.ListItemCollection collListItem = oList.GetItems(camlQuery);

context.Load(collListItem);
context.ExecuteQuery();

litResponse.Text = "";
foreach (SP.ListItem item in collListItem)
{
litResponse.Text += "Title: " + item["Title"].ToString() + "<br/>";
}
}