private void LoadLists() { ClientContext clientContext = new ClientContext(“http: //[Site]“); oWebsite = clientContext.Web; collList = oWebsite.Lists; clientContext.Load(oWebsite, website => website.Title); //Lambda expression para retornar as Listas listInfo = clientContext.LoadQuery( collList.Include( list => list.Title, list => list.Fields.Include( field => field.Title).Where( field => field.Required == true && field.Hidden != true ))); clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed); }
private void onQuerySucceeded( object sender, ClientRequestSucceededEventArgs args) { UpdateUIMethod updateUI = DisplayInfo; this .Dispatcher.BeginInvoke(updateUI); } private void onQueryFailed( object sender, ClientRequestFailedEventArgs args) { MessageBox.Show( "Request failed. " + args.Message + "\n" + args.StackTrace); } private void DisplayInfo() { collList = oWebsite.Lists; listBox1.ItemsSource = listInfo; listBox1.DisplayMemberPath = { collList = oWebsite.Lists; listBox1.ItemsSource = listInfo; listBox1.DisplayMemberPath = "Title" ; } private delegate void UpdateUIMethod(); Example: http://msdn.microsoft.com/en-us/library/ee538971.aspx Method 2: Returns data in the List "General" to a DataGrid using CAML to make filters to return the contents:
private void LoadGrid() { //Context of the SharePoint Site var context = new ClientContext( " http:// [Site]" ); context.Load(context.Web); //return Object List“Geral” List projects = context.Web.Lists.GetByTitle( "Geral" ); context.Load(projects); //CAML Query to filter values from the list CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" + "<Value Type='Number'>0</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>" ; _projectItems = projects.GetItems(camlQuery); context.Load(_projectItems); context.ExecuteQueryAsync(OnRequestSucceeded, null ); }
#region Methods private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args) { Dispatcher.BeginInvoke(BindData); } private void BindData() { //User List "Geral" as List var list = new List<Geral>(); foreach (var li in _projectItems) { list.Add( new Geral { Title = li[ "Title" ].ToString(), Nome = li[ "Nome" ].ToString(), Activo = Convert.ToBoolean(li[ "Activo" ].ToString()) }); } //Add List info into Datagrid dataGrid1.ItemsSource = list; }
if (!TxtTitle.Text.Equals( "" )) { ClientContext clientContext = new ClientContext(TxtUrl.Text); Web oWebsite = clientContext.Web; ListCollection collList = oWebsite.Lists; oList = clientContext.Web.Lists.GetByTitle( "Anuncios" ); ListItem oListItem = oList.AddItem( new ListItemCreationInformation()); oListItem[ "Title" ] = TxtTitle.Text; oListItem[ "Body" ] = TxtBody.Text; oListItem.Update(); clientContext.Load(oList,list => list.Title); clientContext.ExecuteQueryAsync(onQueryInsertSucceeded, onQueryInsertFailed); } else { MessageBox.Show( "Empty!!" ); }
Richard Mueller edited Revision 5. Comment: Replaced RGB values with color names in HTML to restore colors
Richard Mueller edited Revision 4. Comment: Removed (en-US) from title, added tags
Craig Lussier edited Revision 2. Comment: added en-US to tags and title
Thank you for this article!
Great page, André!
This is really very helpful for beginners who want to know about Clienst Side Object Model for silverlight.